SA-MP Forums Archive
Help with car locks - 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: Help with car locks (/showthread.php?tid=195187)



Help with car locks - Perry - 01.12.2010

My question here is how to reapply this function below when "OnVehicleStreamIn " is called. Otherwise this doesn't work.

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext,"/lock",true)) 
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFFFFFAA,"You have to be inside a vehicle.");
        for(new i=0; i < MAX_PLAYERS; i++)
        {
            if(i == playerid) continue;
            SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,1);
        }
        return 1;
    }
    return 0;
}
I've tried this

Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
	SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
}
and doesn't work, I'm a begginer here so any suggestion will be appreciated.


Re: Help with car locks - JaTochNietDan - 01.12.2010

What doesn't work about it? Is the vehicle locked or not locked? Give us some more details

I'm guessing the best way of making a locking system though would be to create a variable in which you store if a vehicle is locked or not. For example:

pawn Код:
new vLocked[MAX_VEHICLES] = -1;
You might want to make your own define for how many vehicles you have to optimize things.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext,"/lock",true))
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFFFFFAA,"You have to be inside a vehicle.");
        for(new i=0; i < MAX_PLAYERS; i++)
        {
            if(i == playerid) continue;
            SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,1);
        }
        vLocked[GetPlayerVehicleID(playerid)] = playerid;
        return 1;
    }
    return 0;
}
pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(vLocked[vehicleid] != forplayerid && vLocked[vehicleid] != -1) SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
    return 1;
}
Note: I use -1 because I store the playerid so we know not to lock it for the person who locked it in the first place


Re: Help with car locks - Perry - 01.12.2010

I try that and when I lock a car, all the cars get lock! and just me can open them xD really weird


Re: Help with car locks - The_Gangstas - 01.12.2010

i thinks its because he set the vlocked outside of the checks.

pawn Код:
if(!strcmp(cmdtext,"/lock",true))
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFFFFFAA,"You have to be inside a vehicle.");
        for(new i=0; i < MAX_PLAYERS; i++)
        {
            if(i == playerid) continue;
            SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,1);
            vLocked[GetPlayerVehicleID(playerid)] = playerid;
        }
        return 1;
    }



Re: Help with car locks - Perry - 01.12.2010

Nope doesn't work still the same problem all the cars are lock and only the player with the id 0 can drive them :S any help here?