Making this code efficiant - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Making this code efficiant (
/showthread.php?tid=443178)
Making this code efficiant -
Luis- - 10.06.2013
Hey! I'm in process of making a drop system for my server, I currently have this code;
pawn Код:
case 14: {
WepPickup[CreateDynamicPickup(325, 1, Pos[0]+random(3), Pos[1]+random(3), Pos[2])] = GetPlayerWeapon(playerid);
WepAmmo = Amount;
}
case 15: {
WepPickup[CreateDynamicPickup(326, 1, Pos[0]+random(3), Pos[1]+random(3), Pos[2])] = GetPlayerWeapon(playerid);
WepAmmo = Amount;
}
case 16: {
WepPickup[CreateDynamicPickup(342, 1, Pos[0]+random(3), Pos[1]+random(3), Pos[2])] = GetPlayerWeapon(playerid);
WepAmmo = Amount;
}
case 17: {
WepPickup[CreateDynamicPickup(343, 1, Pos[0]+random(3), Pos[1]+random(3), Pos[2])] = GetPlayerWeapon(playerid);
WepAmmo = Amount;
}
Now that is only half of the code, seeing as there is a lot of weapons I need to add, I was wondering what I could to do to make it smaller and a lot more cleaner, I was thinking of using an array of some sort but, how would I do it?
Thanks!
Re: Making this code efficiant -
IstuntmanI - 10.06.2013
pawn Код:
new Weapons[ ] = { ID0_Model, ID1_Model, ID2_Model, ID3_Model, ID4_Model, ID5_Model, ETC };
WepPickup[playerid] = CreateDynamicPickup(Weapons[GetPlayerWeapon( playerid )], 1, Pos[0]+random(3), Pos[1]+random(3), Pos[2])] = GetPlayerWeapon(playerid);
WepAmmo = Amount;
- you should make it compatible with your variable
Код:
Weapons[GetPlayerWeapon( playerid )]
- what's in red you should have what you have at switch.
Re: Making this code efficiant -
Luis- - 10.06.2013
Brilliant, thanks mate!