Making this code efficiant
#1

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!
Reply
#2

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;
Код:
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.
Reply
#3

Brilliant, thanks mate!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)