SA-MP Forums Archive
Personal Car Not Working - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Personal Car Not Working (/showthread.php?tid=166845)



Personal Car Not Working - [NWA]Hannes - 10.08.2010

Well, Im working on personal cars on the server, but the server crash when someone enters the test car.

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(GetPlayerVehicleID(playerid) == Testcar)
        {
            new Float:X, Float:Y, Float:Z;
            GetVehiclePos(Fabmobile, X, Y, Z);
            SetPlayerPos(playerid, X, Y, Z);
            SendClientMessage(playerid, 0xFF0000FF, "You are not the owner of this car!");
            GameTextForPlayer(playerid, "~r~Ejected!", 3000, 5);
            TogglePlayerControllable(playerid, false);
            SetTimerEx("Release", 7500, false, "%i", playerid);
        }
    }
    return 1;
}
pawn Код:
forward Release(playerid);
public Release(playerid)
{
    TogglePlayerControllable(playerid, true);
    return 1;
}



Re: Personal Car Not Working - Jacks - 10.08.2010

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(GetPlayerVehicleID(playerid) == Testcar)
        {
            new Float:X, Float:Y, Float:Z;
            GetVehiclePos(Fabmobile, X, Y, Z);
            SetPlayerPos(playerid, X, Y, Z);
            SendClientMessage(playerid, 0xFF0000FF, "You are not the owner of this car!");
            GameTextForPlayer(playerid, "~r~Ejected!", 3000, 5);
            TogglePlayerControllable(playerid, 1);
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}



Re: Personal Car Not Working - [NWA]Hannes - 10.08.2010

Quote:
Originally Posted by Jacks
Посмотреть сообщение
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(GetPlayerVehicleID(playerid) == Testcar)
        {
            new Float:X, Float:Y, Float:Z;
            GetVehiclePos(Fabmobile, X, Y, Z);
            SetPlayerPos(playerid, X, Y, Z);
            SendClientMessage(playerid, 0xFF0000FF, "You are not the owner of this car!");
            GameTextForPlayer(playerid, "~r~Ejected!", 3000, 5);
            TogglePlayerControllable(playerid, 1);
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
You see, the SetPlayerPos is for removing the player from the vehicle, as RemovePlayerFromVehicle performs the exit anim, but with SetPlayerPos it ejects the player in a better way.

And TogglePlayerControllable should be false, as the player should be frozen for 7,5 seconds, the timer should be in too.

And as i said, removeplayerfromvehicle is useless since the player is already ejected at that point.


Re: Personal Car Not Working - DiddyBop - 10.08.2010

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(GetPlayerVehicleID(playerid) == Testcar)
        {
            new Float:X, Float:Y, Float:Z;
            GetVehiclePos(Fabmobile, X, Y, Z);
            SetPlayerPos(playerid, X+2, Y, Z);
            SendClientMessage(playerid, 0xFF0000FF, "You are not the owner of this car!");
            GameTextForPlayer(playerid, "~r~Ejected!", 3000, 5);
            TogglePlayerControllable(playerid, false);
            SetTimerEx("Release", 7500, false, "%i", playerid);
        }
    }
    return 1;
}
now try.


Re: Personal Car Not Working - Mike Garber - 10.08.2010

Easier;
Will lock the car If It's not you, looks more pro and feels more realistic.

pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(GetPlayerVehicleID(playerid) == Testcar)
        new playername[MAX_PLAYER_NAME];
        GetPlayerName(forplayerid, playername, sizeof(playername));
        if(strfind(playername, "YOUR NAME", true) == -1){ //
        SetVehicleParamsForPlayer(vehicleid,forplayerid,0,1); // IF IT IS NOT YOU, LOCK
        }else{
            SetVehicleParamsForPlayer(vehicleid,forplayerid,0,0); // IF IT IS YOU, UNLOCK
        }
    }
    return 0;
}