Pvars...
#1

Ok so I just tried to update my GM with the new PVar system, but in my team based GM, teams aren't being set at all.
pawn Code:
//at top of script
#define TEAM_COPS 1
#define TEAM_CRIMINALS 2
new Team[MAX_PLAYERS];

forward SetPlayerTeamFromClass(playerid, classid);
public SetPlayerTeamFromClass(playerid,classid) //called from OnPlayerRequestClass
{
    // Set their team number based on the class they selected.
    if(classid == 4 || classid == 5 || classid == 6 || classid == 7 || classid == 8 || classid == 9 || classid == 10 || classid == 11 || classid == 12)
    {
        SetPVarInt(playerid, Team, TEAM_COPS);
        SetPVarInt(playerid,HasPlayerChangedTeams,1);
        SetPVarInt(playerid,HasBeenSentObjectives,0);
    }
    else if(classid == 0 || classid == 1 || classid == 2 || classid == 3)
    {
      SetPVarInt(playerid, Team, TEAM_CRIMINALS);
      SetPVarInt(playerid,HasPlayerChangedTeams,1);
      SetPVarInt(playerid,HasBeenSentObjectives,0);
    }
    return 1;
}

public SetPlayerToTeamColor(playerid) //called from OnPlayerSpawn, which also checks for team
{
    if(GetPVarInt(playerid,Team) == TEAM_COPS)  SetPlayerColor(playerid,COPS_COLOR); // blue
    else if(GetPVarInt(playerid,Team) == TEAM_CRIMINALS) SetPlayerColor(playerid,CRIMINALS_COLOR); // red
    return 1;
}
Nothing works. I set every player who connects colour to white when they connect, then set their color based on their team when they spawn.
Did I use PVars wrong?

EDIT: why is everything in there blue?
Reply
#2

Try this:

pawn Code:
//at top of script
#define TEAM_COPS 1
#define TEAM_CRIMINALS 2
new Team[MAX_PLAYERS];

forward SetPlayerTeamFromClass(playerid, classid);
public SetPlayerTeamFromClass(playerid, classid) //called from OnPlayerRequestClass
{
    // Set their team number based on the class they selected.
    if (classid == 4 || classid == 5 || classid == 6 || classid == 7 || classid == 8 || classid == 9 || classid == 10 || classid == 11 || classid == 12)
    {
        SetPVarInt(playerid, Team[playerid], TEAM_COPS);
        SetPVarInt(playerid, HasPlayerChangedTeams, 1);
        SetPVarInt(playerid, HasBeenSentObjectives, 0);
    }
    else if (classid == 0 || classid == 1 || classid == 2 || classid == 3)
    {
      SetPVarInt(playerid, Team[playerid], TEAM_CRIMINALS);
      SetPVarInt(playerid, HasPlayerChangedTeams, 1);
      SetPVarInt(playerid, HasBeenSentObjectives, 0);
    }
    return 1;
}

public SetPlayerToTeamColor(playerid) //called from OnPlayerSpawn, which also checks for team
{
    if (GetPVarInt(playerid, Team[playerid]) == TEAM_COPS) SetPlayerColor(playerid,COPS_COLOR); // blue
    else if (GetPVarInt(playerid, Team[playerid]) == TEAM_CRIMINALS) SetPlayerColor(playerid,CRIMINALS_COLOR); // red
    return 1;
}
Untested.
Reply
#3

Still doesn't work. I think I have tracked the issue down to actually setting the player's teams. I tried using 1 and 2 instead of TEAM_COPS and TEAM_CRIMINALS but that also didn't work. Each player that joins is getting their team set to 0 which is undefined in my GM.
Reply
#4

Bump. Can someone please show me the proper way to use these? <3
Reply
#5

Just realised what i did wrong.

Try this:

pawn Code:
//at top of script
#define TEAM_COPS 1
#define TEAM_CRIMINALS 2

forward SetPlayerTeamFromClass(playerid, classid);
public SetPlayerTeamFromClass(playerid, classid) //called from OnPlayerRequestClass
{
    // Set their team number based on the class they selected.
    if (classid == 4 || classid == 5 || classid == 6 || classid == 7 || classid == 8 || classid == 9 || classid == 10 || classid == 11 || classid == 12)
    {
        SetPVarInt(playerid, "Team", TEAM_COPS);
        SetPVarInt(playerid, "HasPlayerChangedTeams", 1);
        SetPVarInt(playerid, "HasBeenSentObjectives", 0);
    }
    else if (classid == 0 || classid == 1 || classid == 2 || classid == 3)
    {
      SetPVarInt(playerid, "Team", TEAM_CRIMINALS);
      SetPVarInt(playerid, "HasPlayerChangedTeams", 1);
      SetPVarInt(playerid, "HasBeenSentObjectives", 0);
    }
    return 1;
}

public SetPlayerToTeamColor(playerid) //called from OnPlayerSpawn, which also checks for team
{
    if (GetPVarInt(playerid, "Team") == TEAM_COPS) SetPlayerColor(playerid,COPS_COLOR); // blue
    else if (GetPVarInt(playerid, "Team") == TEAM_CRIMINALS) SetPlayerColor(playerid,CRIMINALS_COLOR); // red
    return 1;
}
Reply
#6

Will try now.
EDIT: By doing that I get unused warnings. Must I still create the variables?
EDIT EDIT: Got rid of the variables and it still compiled, though now for some reason you get set to TEAM_COPS regardless of whether your "Team" is set to TEAM_COPS or TEAM_CRIMINALS
Reply
#7

Could you post the warnings please
Reply
#8

This is really confusing. Now I actually get set to a team, but regardless of which class I choose I get set to team 1 which is the cops. Yet I have a function that doesn't let you in a hunter if you're not a cop, and it's not letting me in a hunter ??

I thought maybe it didn't like "TEAM_COPS" and "TEAM_CRIMINALS" but it doesn't seem to be that, since I changed the thing that sets your team to SetPVarInt(playerid,"Team",1); for cops and SetPVarInt(playerid,"Team",2); for criminals but I still get set to team 1 regardless of anything I do. :/

EDIT: I made a cmd showing all the PVars I use, and each one is still being set to 0
Reply
#9

Bump, I redownloaded the server (Windows R5-2), still have same issue. Also, this:
pawn Code:
AddPlayerClass(29,1930.8324,740.1257,10.8203,179.3071,28,300,35,2,0,0); // crims_spawn1
    AddPlayerClass(0,1930.8324,740.1257,10.8203,179.3071,28,300,35,2,0,0); // crims_spawn1
    AddPlayerClass(179,1930.8324,740.1257,10.8203,179.3071,28,300,35,2,0,0); // crims_spawn1
    AddPlayerClass(124,1930.8324,740.1257,10.8203,179.3071,28,300,35,2,0,0); // crims_spawn1

    for(id = 280; id <= 288; id++)
    {
        AddPlayerClass(id,340.0815,2026.1152,22.6406,99.1120,24,70,0,0,0,0); // cops_spawn
    }
gives me all those weapons regardless of what class I choose. Sometimes it even gives me double or triple the ammo!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)