Set a players team from lcass
#1

I'm following this tutorial.
https://sampwiki.blast.hk/wiki/PAWN_tutorial_1
I'm near the bottom, and it says;

SetPlayerTeamFromClass(playerid, classid)
{
if (classid == 0)
{
gTeam[playerid] = TEAM_GROVE;
}
else
{
gTeam[playerid] = TEAM_BALLA;
}
}

Where do I add it? It says;

Place that code OUTSIDE a function in your code (as it is a new function) and put these lines as the first things after the open curly braces in your OnPlayerRequestClass callback (notice the way the variables are not global so we are having to pass them to out function too)

I can't get it to work though, help is appreciated.
Reply
#2

Anyone? This can't be too hard to solve.
Reply
#3

It means that you have to add
pawn Код:
stock SetPlayerTeamFromClass(playerid, classid)
{
    if (classid == 0)
    {
        gTeam[playerid] = TEAM_GROVE;
    }
    else
    {
        gTeam[playerid] = TEAM_BALLA;
    }
}
at the bottom of your script. So, under the latest public function

For the second thing, it means you have to do it like this
pawn Код:
public OnPlayerRequestClass(playerid, classid) {
    SetPlayerTeamFromClass(playerid, classid);
}
Reply
#4

What is that "stock" you added before SetPlayerTeamFromClass?
Reply
#5

Quote:
Originally Posted by SA-MP Wiki
Stocks are a form of function. The only noticeable difference between a stock and a function is that when you don't use a stock, you don't get a warning. Stocks are powerful little tools that allow you to move large repeated bits of code away from the main block, making it easier to edit something that is used in multiple places.
source
Reply
#6

Ah, thank you!
Reply
#7

No problem
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)