PDA

View Full Version : Making this code efficiant


Luis-
10/06/2013, 10:19 PM
Hey! I'm in process of making a drop system for my server, I currently have this code;

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!

IstuntmanI
10/06/2013, 10:22 PM
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;
WepPickup[playerid] - you should make it compatible with your variable
Weapons[GetPlayerWeapon( playerid )] - what's in red you should have what you have at switch.

Luis-
10/06/2013, 10:40 PM
Brilliant, thanks mate!