Check score and skin before spawn.
#1

Hello guys !
Today im stuck with this :
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerTeamFromClass(playerid, classid);
    SetPlayerPos(playerid, 1491.4349,-871.7689,60.0094);
    SetPlayerFacingAngle(playerid,311.0488);
    SetPlayerCameraPos(playerid, 1496.0518,-867.3990,60.9751);
    SetPlayerCameraLookAt(playerid, 1491.4349,-871.7689,60.0094);
    pClass[playerid] = classid;
    if(classid == 0)
    {
        GameTextForPlayer(playerid, "~g~VOJSKA:PESADIJA", 1000, 4);
    }
    if(classid == 1)
    {
        GameTextForPlayer(playerid, "~g~VOJSKA:TENKISTI", 1000, 4);
        if(GetPlayerScore(playerid) <= 49)
        {
            SendClientMessage(playerid,-1,"[SERVER]: Morate posedovati minimum 50 skora za ovu klasu!");//Error msg
            return 0;
        }
    }
    if(classid == 2)
    {
        if(GetPlayerScore(playerid) <= 69)
        {
            SendClientMessage(playerid,-1,"[SERVER]: Morate posedovati minimum 70 skora za ovu klasu!");
            return 0;
        }
    }
    if(classid == 3)
    {
        GameTextForPlayer(playerid, "~g~POBUNJENICI:PESADIJA", 1000, 4);
    }
    if(classid == 4)
    {
        GameTextForPlayer(playerid, "~g~POBUNJENICI:TENKISTI", 1000, 4);
        if(GetPlayerScore(playerid) <= 49)
        {
            SendClientMessage(playerid,-1,"[SERVER]: Morate posedovati minimum 50 skora za ovu klasu!");
            return 0;
        }
    }
    if(classid == 5)
    {
        GameTextForPlayer(playerid, "~g~POBUNJENICI:PILOTI", 1000, 4);
        if(GetPlayerScore(playerid) <= 69)
        {
            SendClientMessage(playerid,-1,"[SERVER]: Morate posedovati minimum 70 skora za ovu klasu!");
            return 0;
        }
    }
    return 1;
}
I want script to check player score before he can pick skin.. i tried to do this under
pawn Код:
public OnPlayerRequestSpawn(playerid)
but i guess there is no chance to check classid.
I enter in server, i get GameTextForPlayer and Error message even before i click spawn button,and if i click it,it spawns me and i have 0 score.
Reply
#2

You need to set the player's score before you can get the player score. When loading the player's stats I suggest you set the player's score to whatever has been saved.

I think you just forgot to add it.

https://sampwiki.blast.hk/wiki/SetPlayerScore
Reply
#3

Okey i guess that will work.. i will try it tomorrow, however what to do with error msgs ? How to make them "wait" before player click on spawn.. Server send them while players still choosing..
Thanks for your fast answer and support.
Reply
#4

You should store the classid in a global variable and then under OnPlayerSpawn you can basically just do what you've done here. But it'll only be called once the player has chosen a skin. Otherwise you could put all of this on a timer but I suggest doing the first option. I see you use pClass[playerid] use that and then put all your script under OnPlayerSpawn. Here is what it could look like.

PHP код:
public OnPlayerRequestClass(playeridclassid)
{
    
SetPlayerTeamFromClass(playeridclassid);
    
SetPlayerPos(playerid1491.4349,-871.7689,60.0094);
    
SetPlayerFacingAngle(playerid,311.0488);
    
SetPlayerCameraPos(playerid1496.0518,-867.3990,60.9751);
    
SetPlayerCameraLookAt(playerid1491.4349,-871.7689,60.0094);
    
pClass[playerid] = classid;
    
SetPVarInt(playerid,"NewlySpawned",0);
    return 
1;
}
public 
OnPlayerSpawn(playerid)
{
    if(
GetPVarInt(playerid"NewlySpawned") == 0)
    {
        if(
pClass[playerid] == 0)
        {
            
GameTextForPlayer(playerid"~g~VOJSKA:PESADIJA"10004);
            
SetPVarInt(playerid,"NewlySpawned",1);
        }
        if(
pClass[playerid] == 1)
        {
            
GameTextForPlayer(playerid"~g~VOJSKA:TENKISTI"10004);
            
SetPVarInt(playerid,"NewlySpawned",1);
            if(
GetPlayerScore(playerid) <= 49)
            {
                
SendClientMessage(playerid,-1,"[SERVER]: Morate posedovati minimum 50 skora za ovu klasu!");//Error msg
                
return 0;
            }
        }
        if(
pClass[playerid] == 2)
        {
            
SetPVarInt(playerid,"NewlySpawned",1);
            if(
GetPlayerScore(playerid) <= 69)
            {
                
SendClientMessage(playerid,-1,"[SERVER]: Morate posedovati minimum 70 skora za ovu klasu!");
                return 
0;
            }
        }
        if(
pClass[playerid] == 3)
        {
            
GameTextForPlayer(playerid"~g~POBUNJENICI:PESADIJA"10004);
            
SetPVarInt(playerid,"NewlySpawned",1);
        }
        if(
pClass[playerid] == 4)
        {
            
GameTextForPlayer(playerid"~g~POBUNJENICI:TENKISTI"10004);
            
SetPVarInt(playerid,"NewlySpawned",1);
            if(
GetPlayerScore(playerid) <= 49)
            {
                
SendClientMessage(playerid,-1,"[SERVER]: Morate posedovati minimum 50 skora za ovu klasu!");
                return 
0;
            }
        }
        if(
pClass[playerid] == 5)
        {
            
GameTextForPlayer(playerid"~g~POBUNJENICI:PILOTI"10004);
            
SetPVarInt(playerid,"NewlySpawned",1);
            if(
GetPlayerScore(playerid) <= 69)
            {
                
SendClientMessage(playerid,-1,"[SERVER]: Morate posedovati minimum 70 skora za ovu klasu!");
                return 
0;
            }
        }
    }
    else if(
GetPVarInt(playerid"NewlySpawned") == 1)
    {
        
//Add everything in here that you want to happen if player has died. Or is spawning that hasn't just chosen a skin.
    
}
    return 
1;

Please note that this is untested and could contain errors.
Reply
#5

Thanks !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)