SetPlayerTeam not preventing damage
#1

Under OnPlayerSpawn I have this:

pawn Код:
SetPlayerTeam(playerid, playersTeam[playerid]);
I have this timer:

pawn Код:
ptask PlayerUpdate[1000](playerid)
{  
    if(!InEvent[playerid])
    {
        SetPlayerTeam(playerid, playersTeam[playerid] + 20);
    }
   
    return 1;
}
I have a command which shows the playersTeam variable along with GetPlayerTeam:

pawn Код:
COMMAND:myteam(playerid, params[]) return SendServerMessageEx(playerid, "urteam: %d, %d", playersTeam[playerid], GetPlayerTeam(playerid));


My friend and I are both on my server and when we type /myteam, it shows 1, 21 for both of us. When one of us shoots one another, we take damage when we aren't supposed to. I don't know why SetPlayerTeam isn't preventing the damage.
Reply
#2

Well, SetPlayerTeam prevents damage for players in the same team, but you cleary assign every player an own team.

edit: read the code wrong, you put them in the same team of course.
Players in the same team seem to take damage anyways sometimes. I think this is releated to lag.
Reply
#3

No I don't. A friend and I both did /myteam and it displayed the same team but we still took damage from each other.
Reply
#4

To not use MyTeam:

pawn Код:
forward MyTeam(playerid);
public MyTeam(playerid)
{
    if(gTeam[playerid] == TEAM_FBI)
    {
    SendClientMessage(playerid, COLOR_ORANGE,"You are in Team FBI!");
    }
    else if (gTeam[playerid] == TEAM_KILLER)
    {
    SendClientMessage(playerid, COLOR_ORANGE,"You are in Team KILLER!");
    }
    return 1;
}
The command:
pawn Код:
CMD:myteam(playerid, params[])
{
    MyTeam(playerid);
    return 1;
}
Example:

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(gTeam[playerid] == FBI)
    {
        new rand = random(sizeof(fbiSpawn));
        SetPlayerPos(playerid,fbiSpawn[rand][0],fbiSpawn[rand][1],fbiSpawn[rand][2]);
        SetPlayerFacingAngle(playerid,fbiSpawn[rand][3]);
        SetPlayerColor(playerid,fbicolor);
        SetPlayerTeam(playerid,FBI);
    }
    else if(gTeam[playerid] == KILLERS)
    {
        new rand = random(sizeof(KillersSpawn));
        SetPlayerPos(playerid,KillersSpawn[rand][0],KillersSpawn[rand][1],KillersSpawn[rand][2]);
        SetPlayerFacingAngle(playerid,KillersSpawn[rand][3]);
        SetPlayerColor(playerid,Killerscolor);
        SetPlayerTeam(playerid,KILLERS);
    }
    return 1;
}
Reply
#5

Maybe this function, would work?

pawn Код:
forward SettingPlayerTeam();
public SettingPlayerTeam()
{
    foreach(Player, playerid) {
        SetPlayerTeam(playerid, gTeam[playerid]);
    }
    return 1;
}
Reply
#6

Please don't reply unless you know what you're talking about.
Reply
#7

Considering the code you have provided, you seam to set all players teams with "playersTeam[playerid]" when they spawn without actually setting the variables value first(Unless you have not shown us yet) which i think will be recognised as 0 and then your call a 1 second timer over and over and set that same variable to +20(Which then would be 20)

So what i have established from this thread, is you have somehow confused yourself with a variable(Or do not fully understand how a variable works yet)

This is how i would create a team system.


pawn Код:
#include <a_samp>

//STEP 1: First we must define our teams(tell pawno what our teams are going to be called)
#define TEAM_ONE 0//Team 1 will now be recognised as TEAM_ONE or simply 0
#define TEAM_TWO 1//Team 2 will now be recognised as TEAM_TWO or simply 1
//We also need to create a player variable to use to check/set playerid's team/s
new GetTeam[MAX_PLAYERS];

//STEP 2: We now add AddPlayerClass functions for each of our skins, we will use 2 skins today, 1 per team.
public OnGameModeInit()
{
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);//Team 1 skin (Line 1)
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);//Team 2 skin (Line 2)
    return 1;
}

//STEP 3: Now we need to create a system so the player can choose a skin before spawning, while we check
//what skin they are looking at and set the team id to the AddPlayerClass lines.
public OnPlayerRequestClass(playerid, classid)
{
    switch(classid)//The classid parameter is the line count of the AddPlayerClass function/s under OnGameModeInit
    {
        case 0://Line 1 (Team 1 skin)
        {
            GameTextForPlayer(playerid, "Team One", 5000, 5);//Let the player know what team(skin) there looking at
            GetTeam[playerid] = TEAM_ONE;//Set there player variable to the team id
        }
        case 1://Line 2 (Team 2 skin)
        {
            GameTextForPlayer(playerid, "Team Two", 5000, 5);//Let the player know what team(skin) there looking at
            GetTeam[playerid] = TEAM_TWO;//Set there player variable to the team id
        }
    }
    return 1;
}

//LAST STEP: In this step i will show you how you can use your new class system.
public OnPlayerSpawn(playerid)
{
    if(GetTeam[playerid] == TEAM_ONE)
    {
        //Set Team 1 spawn locations/weapons/colors etc.
    }
    else if(GetTeam[playerid] == TEAM_TWO)
    {
        //Set Team 2 spawn locations/weapons/colors etc.
    }
    return 1;
}
//The player will continue to spawn in there selected team/skin until they are forced to selection, via command or
//relogging to go back to there first spawn.

//The rest is straight forward and if you wish to send players back to class selection(without relogging again)
//Simply use: ForceClassSelection(playerid);





//Blasphemy
Reply
#8

If you actually looked at my /myteam command, you would see that it displays the person's team variable and the GetPlayerTeam of the person. My friend and I both had 1, 21 which means the variable is 1 and GetPlayerTeam is 21. I do set the variable in my script.
Reply
#9

Well, i have just shown you how to do it a more easier way.

PS: Try removing the "sizeof" from the variable in the "for" loop.

EDIT: Why go: "sizeof(20)" ?
Reply
#10

What sizeof are you talking about and how do you know that my system isn't like yours. Also, yours doesn't include SetPlayerTeam in it. Don't reply if you don't know what you're talking about.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)