SA-MP Forums Archive
Vehicle system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Vehicle system (/showthread.php?tid=343318)



Vehicle system - iGetty - 17.05.2012

I have a vehicle system, that loads teamid's and things.

I was wondering, how could I get it so that I can check it against the teamid under OnPlayerStateChange?

For instance:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(GetPlayerTeam(playerid) != THEVEHICLEVAR)
    {
        SendClientMessage(playerid, WHITE, "This vehicle isn't for you.");
        RemovePlayerFromVehicle(playerid);
    }
    else
    {
        return 1;
    }
    return 1;
}
Here is my vehicle system:

pawn Код:
stock LoadVehicles()
{
    new
        Str[128],
        dModel,
        Float:VX,
        Float:VY,
        Float:VZ,
        Float:VA,
        Team,
        col1,
        col2,
        vTotal;

    mysql_query("SELECT * FROM `vehicles`");
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(Str))
        {
            sscanf(Str, "p<|>iffffiii", dModel, VX, VY, VZ, VA, Team, col1, col2);
            CreateVehicle(dModel, VX, VY, VZ, VA, col1, col2, -1);
            vTotal++;
        }
    }
    mysql_free_result();
    printf("%i vehicles loaded from the MySQL Database.", vTotal);
    return 1;
}


//this is for saving them after a command to create them

stock SaveVehicle(Float:VX, Float:VY, Float:VZ, Float:VA, dModel, Team, col1, col2)
{
    new
        Query[1024];

    format(Query, sizeof(Query), "INSERT INTO `vehicles` (VehicleModel, VehicleX, VehicleY, VehicleZ, VehicleAngle, Team, Colour1, Colour2) VALUES(%d, %f, %f, %f, %f, %d, %i, %i)",
    dModel, VX, VY, VZ, VA, Team, col1, col2);

    mysql_query(Query);
    mysql_free_result();
    return 1;
}

//here is the command

command(addvehicle, playerid, params[])
{
    if(Player[playerid][AdminLevel] >= 5)
    {
        new
            Float:VX,
            Float:VY,
            Float:VZ,
            Float:VA,
            Team,
            col1,
            col2,
            dModel = GetVehicleModel(GetPlayerVehicleID(playerid)),
            vehicleid = GetPlayerVehicleID(playerid),
            Msg[128];
        if(sscanf(params, "dii", Team, col1, col2)) return SendClientMessage(playerid, WHITE, "Server: /addvehicle [teamid] [color 1] [color 2]");
        {
            GetVehiclePos(vehicleid, VX, VY, VZ);
            GetVehicleZAngle(vehicleid, VA);

            if(IsPlayerInAnyVehicle(playerid))
            {
                SaveVehicle(Float:VX, Float:VY, Float:VZ, Float:VA, dModel, Team, col1, col2);
                format(Msg, sizeof(Msg), "A new vehicle Has Been dynamically added. Model: (%d).", dModel);
                return SendClientMessage(playerid, WHITE, Msg);
            }
            else return SendClientMessage(playerid, WHITE, "You must be in a vehicle!");
        }
    }
    else return SendClientMessage(playerid, WHITE, NotAllowed);
}
So how could I check if the player is in the same team as the vehicles team slot?


Thanks!


Re: Vehicle system - Ballu Miaa - 17.05.2012

Arent you using any Tea variables like: gTeams or any kind of clan/faction for player. The make one i'd say. Use gTeams with an enum so that you can create team variables. Use those variables in the faction system when the player is been assigned the faction/clan/team.

Grab that code you made to check the player is in the team. Then use it under OnPlayerUpdate(playerid) callback.


Re: Vehicle system - iGetty - 17.05.2012

That made no sense as to what I'm asking.

I've got the teams added, yes.

I use GetPlayerTeam not gTeam.

I prefer it that way, with the #define's.

I just want to know; will this work?

pawn Код:
stock LoadVehicles()
{
    new
        Str[128],
        dModel,
        Float:VX,
        Float:VY,
        Float:VZ,
        Float:VA,
        Team,
        col1,
        col2,
        vTotal;

    mysql_query("SELECT * FROM `vehicles`");
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(Str))
        {
            sscanf(Str, "p<|>iffffiii", dModel, VX, VY, VZ, VA, Team, col1, col2);
            CreateVehicle(dModel, VX, VY, VZ, VA, col1, col2, -1);
            vTotal++;
        }
    }
    mysql_free_result();
    printf("%i vehicles loaded from the MySQL Database.", vTotal);
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        VehicleTeam[i] = Team;
    }
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(GetPlayerTeam(playerid) == VehicleTeam[GetPlayerVehicleID(playerid)])
        {
            return 1;
        }
        else
        {
            SendClientMessage(playerid, WHITE, "You're not allowed to drive this vehicle.");
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}



Re: Vehicle system - RedWingz - 17.05.2012

Hmm, I've had this problem before, But I can't remember how I fixed it...
Lemme look on my script, I've got something like that on it.
I'll get back to you soon and then I'll help you.


Re: Vehicle system - iGetty - 17.05.2012

I fixed it

With the code I posted above it worked