Defining vehicle id
#1

Код:
CMD:vehlock(playerid, params[])
{
    new Float: x, Float: y, Float: z;
    if(PlayerInfo[playerid][pVehicleKeysFrom] != INVALID_PLAYER_ID)
	{
        new ownerid = PlayerInfo[playerid][pVehicleKeysFrom];
        if(IsPlayerConnected(ownerid))
		{
            new d = PlayerInfo[playerid][pVehicleKeys];
            if(PlayerVehicleInfo[ownerid][d][pvId] != INVALID_PLAYER_VEHICLE_ID) GetVehiclePos(PlayerVehicleInfo[ownerid][d][pvId], x, y, z);
            if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
			{
                if(PlayerVehicleInfo[ownerid][d][pvLock] > 0)
				{
                    if(PlayerVehicleInfo[ownerid][d][pvLocked] == 0)
					{
                        GameTextForPlayer(playerid,"~r~Vehicle Locked!",5000,6);
                        PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                        PlayerVehicleInfo[ownerid][d][pvLocked] = 1;
                        LockPlayerVehicle(ownerid, PlayerVehicleInfo[ownerid][d][pvId], PlayerVehicleInfo[ownerid][d][pvLock]);
                        return 1;
                    }
                    else
					{
                        GameTextForPlayer(playerid,"~g~Vehicle Unlocked!",5000,6);
                        PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                        PlayerVehicleInfo[ownerid][d][pvLocked] = 0;
                        UnLockPlayerVehicle(ownerid, PlayerVehicleInfo[ownerid][d][pvId], PlayerVehicleInfo[ownerid][d][pvLock]);
                        return 1;
                    }
                }
This is a made up script and I am just practicing and trying new stuff on it.
The code continues after the '}' I just don't think that it's neccessary.
Anyways I have been trying to change it so whenever I unlock the vehicle it'll say the name of the vehicle and then unlocked (e.g: "Turismo Unlocked") and whenever I lock it it'll say the name of the vehicle and then locked (Turismo Locked).

I tried to edit this:

Код:
GameTextForPlayer(playerid,"~r~%s Locked!",5000,6, VehicleName[PlayerVehicleInfo[pvModelId] - 400]);
I did the same for the 'unlocked' part but it returned me this:
Код:
XXXX\XXXX\XXXX\XXXX.pwn(57967) : error 033: array must be indexed (variable "PlayerVehicleInfo")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
I am pretty new to scripting so if this question is kinda stupid then.. eh..
Can anyone help me out?
If possible paste the code that it'll work don't only tell me what to do lol because I don't really know all the abbreviations lol.

Thanks!
Reply
#2

So GameTextForPlayer only takes in 4 arguments/parameters: https://sampwiki.blast.hk/wiki/GameTextForPlayer

playerid -> which player to show
string[] -> the text you want to present
time -> the amount of time it will be displayed in miliseconds
style -> style number

So what is wrong with
Код:
GameTextForPlayer(playerid,"~r~%s Locked!",5000,6, VehicleName[PlayerVehicleInfo[pvModelId] - 400]);

compared to 

GameTextForPlayer(playerid,"~r~Vehicle Locked!",5000,6);
I can see in total two incorrect things, first thing is first:
1) The amount of parameters are incorrect, as I stated above it may only have 4 but yours have 5. What you are trying to do is formatting, sadly it doesn't work like that. Wouldn't it be wonderful if it did? Well it can with emits for example, also in other ways, but don't worry about that for now. Use the normal "format" as you did in the previous example you provided (first one).

2) In your fifth argument you are using VehicleName which is fine but the error is displaying PlayerVehicleInfo for a reason and that is because it is predefined (somewhere in your script) to be 3D-array. Now what does that mean? It means that you are more or less creating a table that is in a 3-dimensional world.

You have rows going in the X direction, you have columns going in the Y direction and ontop of that you have yet other rows going in Z direction. I just named them X, Y, Z because 3D is usually mentioned with coordinates by the way. So that means that, if it's initialized to be a 3-dimensional array, it has to stay that way, it absolutely has to. So what to do here? I can see in your previous code that you have used something like:
Код:
PlayerVehicleInfo[ownerid][d][pvId]
It's a really easy fix, you just add the first two dimensions and add them before [pvModelId]. So "PlayerVehicleInfo[ownerid][d][pvModelId]".

If any other questions just feel free to poke, we're a friendly SA-MP community as long as you don't ask for free gamemodes you should be fine lmao.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)