This is possible dynamically, this trick allows you to bypass the class limit of SA-MP. Here is the trick or algorithm to do this :
To detect if right arrow or left was pressed:
Firstly add three classes(blank classes) using AddPlayerClass, this should always be three. These three classes are not used by players, they are just used to check if player pressed right or left arrow on spawn button. Now the trick is to firstly make a global variable and store the last class id in it. There will always be three classes because we added three. Now hook OnPlayerRequestClass if lastclassid was 0 and classid passed in function is 1 that means
right button was pressed as classid increased and if classid is 2 this means
left button was pressed as classid decreased( if you decrease 1 from 0 then classid will be 2 as there are only three classes, i.e., 0, 1 and 2). Similarly you have to check for lastid 1 and 2.
Adding Dynamic Class:
Now make a global variable to store class info. It should be of this structure:
PHP код:
#define MAX_CLASS 10 // keep this according to your needs as servers mostly dotn have more than 10 classes, you can increase it to any number
enum classEnum{
cskin, Float:cx, Float:cy, Float:cz, Float:cAngle, cweapon1, cweapon1_ammo, cweapon2, cweapon2_ammo, cweapon3, cweapon3_ammo, cteamid
}
new Classes[MAX_CLASS][classEnum];
Make a counter variable that keeps track of last classid added(make it -1 at start).
Hook AddPlayerClass and AddPlayerClassEx.
Increase counter variable by 1.
Add new class info inside variable 'Classes' at index of counter.
Return counter.
Now you see the class is not really added its info is just added to a variable.
The Main algorithm with above two steps combined:
Now make a global variable say currentClass[MAX_PLAYERS] to keep track of player's current
dynamic class.
Now go back to the code to check left and right button. If right button was pressed increase currentClass by 1 and if left button was pressed decrease currentClass by 1. Use info in 'Classes' at index currentClass to set player spawn info using
SetSpawnInfo and SetPLayerSkin.
If currentClass is 0 and left button is pressed so it cannot be decreased anymore so set currentClass equal to 'counter' ,i.e., the last class added.
And if currentClass is equal to counter and right button is pressed that means currentClass is at last class added index and can't be increased so set current class to 0 so that it starts again from 0 class when it reaches last class.
Removing Classes: Setting counter equal to -1 again will remove all dynamic classes
Rough Code : http://pastebin.com/e0sxc9XL *
This code is not tested just a rough code that i have written quickly. I didn't even compiled the code so corrections will probably be needed.