/fixveh help -
darkvsoul36 - 12.05.2012
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.
Re: /fixveh help -
SnG.Scot_MisCuDI - 12.05.2012
pawn Код:
if (!strcmp("/fixveh", cmdtext))
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not in a vehicle!");
RepairVehicle(GetPlayerVehicleID(playerid));
return 1;
}
}
Re: /fixveh help -
Mimic - 12.05.2012
Try using these
pawn Код:
if(!IsPlayerInAnyVehicle(playerid))
pawn Код:
RepairVehicle(GetPlayerVehicleID(playerid));
EDIT: ^ Beat me to it haha
Re: /fixveh help -
AndreT - 12.05.2012
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.
Re: /fixveh help -
darkvsoul36 - 12.05.2012
Thanks guys!
Re: /fixveh help -
sniperwars - 12.05.2012
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;
}
Re: /fixveh help -
RedWingz - 12.05.2012
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.
Re: /fixveh help -
darkvsoul36 - 14.05.2012
What's the difference in ZCMD and strcmp?
Also... What do you use "!" for in the following?
Код:
if(!IsPlayerInAnyVehicle(playerid))
Re: /fixveh help -
Faisal_khan - 14.05.2012
! 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.
Re: /fixveh help -
darkvsoul36 - 14.05.2012
So by using:
Код:
if(!IsPlayerInAnyVehicle(playerid))
It is doing a command when a player is
not in a vehicle?