Remove a player class.
#1

I added player class with 'AddPlayerClass' from a FS.
FS gets unloaded.
Server Restarts, using changemode rcon command.
New FS gets loaded.

The new FS has it's own player class, but now I have the old class selection skins along with new one. I had 5 skins before now 10 and keeps on adding...

Anyway to remove the PlayerClass after GM get's unloaded?
Reply
#2

Remove the "AddPlayerClass" lines from the new fs
Reply
#3

I could have done it, but I need those new class for new things.. Classes are different..
Reply
#4

You should add the player class's in the gamemode so it doesn't create loads of classes every time the FS is loaded, or you can set a variable in the gamemode to say that the classes are already loaded and get the FS to check it.

Or hook it to OnGameModeInit?
Reply
#5

But the problem is all of my filterscripts have their own classes and I need those according to those filerscripts.
Reply
#6

https://sampforum.blast.hk/showthread.php?tid=570883
You can find Y-classes in there which can do what you want (dynamically adding and deleting classes).
Reply
#7

You could load skins from files.... if thats what u mean
Reply
#8

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{
    
cskinFloat:cxFloat:cyFloat:czFloat:cAnglecweapon1cweapon1_ammocweapon2cweapon2_ammocweapon3cweapon3_ammocteamid
}
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.
Reply
#9

But with that code wouldn't player see the CJ skin?
Reply
#10

Nope see the rough code when ever player changes class the hooked OnPLayerRequestClass performs SetSpawnInfo along with SetPlayerSkin. Didnt test but it should work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)