Hallöchen, liebe Brötchen,
ich habe eine kleine, aber feine DM Arena gescriptet, in der ich ein internes Event machen möchte. Es handelt sich dabei um einen Waffenspawn, der immer im 3min Abstand vorkommen soll.
Zunächst erstelle ich einen Array, der die möglichen Spawnpositionen beinhält.
new Float:RandomSpawnsBF_Minigun[][4] =
{
{261.7219, 1807.7024, 25.4985},
{267.7146, 1895.2715, 25.4985},
{233.9313, 1934.8359, 25.4985},
{162.3813, 1933.1227, 25.4985},
{104.4367, 1901.1390, 25.4985},
{113.7279, 1814.4298, 25.4985},
{166.4796, 1850.0391, 25.4985}
};
Nun lasse ich alle im DM befindlichen Pickups unter OnGameModeInit erstellen, darunter auch die Minigun, die ich random an einem der in "RandomSpawnsBF_Minigun" angegebenen Spawnpunkte spawnt.
public OnGameModeInit()
{
//9 weitere Waffenpickups (BF_WEAPON[0] bis BF_WEAPON[9])
new Random = random(sizeof(RandomSpawnsBF_Minigun));
BF_WEAPON[10] = CreateDynamicPickup(362, 1, RandomSpawnsBF_Minigun[Random][0], RandomSpawnsBF_Minigun[Random][1], RandomSpawnsBF_Minigun[Random][2], 7, -1, -1, 100.0);
return DM_OnGameModeInit();
}
Als nächstes lege ich fest, was passieren soll, wenn die Pickups aufgehoben werden.
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
//if-Abfragen für BF_WEAPON[0] bis BF_WEAPON[9]...
else if(pickupid == BF_WEAPON[10])
{
GivePlayerWeapon(playerid, MINIGUN, 300);
DestroyDynamicPickup(pickupid);
}
for(new i; i < 10; i++)
{
switch (i)
{
case 0..9: if(pickupid == BF_WEAPON[i]) SetTimerEx("PickupRespawn", 30*1000, false, "i", BF_WEAPON[i]); //30s Respawnzeit bei 0 bis 9
case 10: if(pickupid == BF_WEAPON[i]) SetTimerEx("MinigunRespawn", 3*60*1000, false, "i", BF_WEAPON[i]); //3min Respawnzeit bei 10
}
}
return _OnPlayerPickUpDynamicPickup(playerid, pickupid);
}
Timer
forward PickupRespawn(pickupid);
public PickupRespawn(pickupid)
{
if(pickupid == BF_WEAPON[0]) return BF_WEAPON[0] = CreateDynamicPickup(342, 1, 120.5242, 1934.8777, 22.7578, 7, -1, -1, 100.0); //Grenade
if(pickupid == BF_WEAPON[1]) return BF_WEAPON[1] = CreateDynamicPickup(342, 1, 279.4142, 1829.5718, 21.4766, 7, -1, -1, 100.0); //Grenade
if(pickupid == BF_WEAPON[2]) return BF_WEAPON[2] = CreateDynamicPickup(342, 1, 116.2530, 1875.0065, 22.4375, 7, -1, -1, 100.0); //Grenade
if(pickupid == BF_WEAPON[3]) return BF_WEAPON[3] = CreateDynamicPickup(342, 1, 136.4600, 1874.9723, 22.4375, 7, -1, -1, 100.0); //Grenade
if(pickupid == BF_WEAPON[4]) return BF_WEAPON[4] = CreateDynamicPickup(360, 1, 189.9938, 1940.4785, 17.6406, 7, -1, -1, 100.0); //Heat Seeker
if(pickupid == BF_WEAPON[5]) return BF_WEAPON[5] = CreateDynamicPickup(360, 1, 206.2279, 1932.8312, 23.2422, 7, -1, -1, 100.0); //Heat Seeker
if(pickupid == BF_WEAPON[6]) return BF_WEAPON[6] = CreateDynamicPickup(360, 1, 144.0044, 1850.1791, 25.2610, 7, -1, -1, 100.0); //Heat Seeker
if(pickupid == BF_WEAPON[7]) return BF_WEAPON[7] = CreateDynamicPickup(360, 1, 211.4619, 1809.8109, 25.1172, 7, -1, -1, 100.0); //Heat Seeker
if(pickupid == BF_WEAPON[8]) return BF_WEAPON[8] = CreateDynamicPickup(360, 1, 146.3869, 1907.3638, 26.3924, 7, -1, -1, 100.0); //Heat Seeker
if(pickupid == BF_WEAPON[9]) return BF_WEAPON[9] = CreateDynamicPickup(360, 1, 197.3199, 1835.0059, 23.2422, 7, -1, -1, 100.0); //Heat Seeker
return 1;
}
forward MinigunRespawn(pickupid);
public MinigunRespawn(pickupid)
{
if(IsValidDynamicPickup(BF_WEAPON[10])) DestroyDynamicPickup(BF_WEAPON[10]);
if(pickupid == BF_WEAPON[10])
{
new Random = random(sizeof(RandomSpawnsBF_Minigun));
BF_WEAPON[10] = CreateDynamicPickup(362, 1, RandomSpawnsBF_Minigun[Random][0], RandomSpawnsBF_Minigun[Random][1], RandomSpawnsBF_Minigun[Random][2], 7, -1, -1, 100.0);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(GetPlayerVirtualWorld(i) == 7)
{
GameTextForPlayer(i, "Minigun Event!", 5000, 4);
}
}
}
return 1;
}
Das Ganze funktioniert dennoch nicht. Die Minigun wird zunächst erstellt, aber sobald ich sie aufnehme, respawnt sie nicht.