/fixveh help
#1

Hey guys/girls. I am new with scripting and have been getting a few commands to work without errors. I wanted to create a command to fix a players vehicle. This command would be used by the player to fix their own vehicle. I tried a few variations and a few days and have not developed a solution. Could someone enlighten me onto what i'm doing wrong? The code is:

Код:
		if (strcmp("/fixveh", cmdtext, true) == 0)
		{
		    new vehicleid;
			IsPlayerInVehicle(playerid, vehicleid);
			RepairVehicle(vehicleid);
			return 1;
		}
Thanks!

P.S. With the code above, I am able to compile, run, and play on the server. However, when I use the command in a vehicle, it does not work.
Reply
#2

pawn Код:
if (!strcmp("/fixveh", cmdtext))
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not in a vehicle!");
        RepairVehicle(GetPlayerVehicleID(playerid));
        return 1;
    }
}
Reply
#3

Try using these

pawn Код:
if(!IsPlayerInAnyVehicle(playerid))
pawn Код:
RepairVehicle(GetPlayerVehicleID(playerid));
EDIT: ^ Beat me to it haha
Reply
#4

This might be confusing for a beginner, but I have a solution for such commands/parts of script using only one native function.

pawn Код:
if(!strcmp(cmd, "/fixveh", true))
{
    new vID = GetPlayerVehicleID(playerid);
    if(vID != 0)
    {
        RepairVehicle(vID);
    }
    return 1;
}
What's the benefit from this? You might start arguing me over the necessity of such "optimization", but theoretically speaking this is faster than a command that first calls IsPlayerInAnyVehicle and then GetPlayerVehicleID. And further on, if you're going to do more things with the vehicle ID, you're going to need to store it in a variable anyways (or it would be good to do so).

GetPlayerVehicleID(playerid) returns 0 when the player isn't in a vehicle, so this is an helpful thing to keep in mind.
Reply
#5

Thanks guys!
Reply
#6

Why not use ZCMD ? It's faster and much better than strcmp:

pawn Код:
COMMAND:fixveh(playerid, params[])
{
     if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not in a vehicle!");
     RepairVehicle(GetPlayerVehicleID(playerid));
     return 1;
}
Reply
#7

Use this:

pawn Код:
if(!strcmp("/repair", cmdtext))
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not in a vehicle!");
        RepairVehicle(GetPlayerVehicleID(playerid));
        SendClientMessage(playerid, COLOR_GREEN, "You have repaired your vehicle!");
        return 1;
    }
Much easier.
Reply
#8

What's the difference in ZCMD and strcmp?
Also... What do you use "!" for in the following?
Код:
if(!IsPlayerInAnyVehicle(playerid))
Reply
#9

! means is "not equal to".
ZCMD is a command processor while strcmp is not and ZCMD is fast but the fastest of all is YCMD.
Reply
#10

So by using:

Код:
if(!IsPlayerInAnyVehicle(playerid))
It is doing a command when a player is not in a vehicle?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)