setcarhp command - 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)
+--- Thread: setcarhp command (
/showthread.php?tid=620196)
setcarhp command -
XpoZzA - 27.10.2016
Hello, I wanna have a command that it's usage is: "/setcarhp [Target Vehicle ID] [Health]."
How can I edit the vehicle's HP, and how can I make it by the vehicle ID, and how can I check if this vehicle ID even exists? thanks!
EDIT:
I made it to here:
Код:
CMD:setcarhp(playerid, params[]){
new vehicleid, health;
if(sscanf(params, "ui", vehicleid, health))return SendClientMessage(playerid, 0x33AA33AA, "USAGE: /setcarhp[Target Vehicle ID] [Health]");
if(!IsValidVehicle(vehicleid)) return SendClientMessage(playerid, 0x33AA33AA, "This vehicle ID isn't valid..");
if(health < 250 || health > 1250) return SendClientMessage(playerid, 0x33AA33AA, "That health isn't realistic");
SetVehicleHealth(vehicleid, health);
SendClientMessage(playerid, 0x33AA33AA, "You changed the health of the vehicle.");
return 1;
}
I have one error, can I have some help?
Код:
C:\Servers\racing_samp\gamemodes\race.pwn(1594) : error 017: undefined symbol "IsValidVehicle"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
Re: setcarhp command -
Dignity - 27.10.2016
You use scanf to do this. There are other methods but in most cases you won't need to use them.
You should also use zcmd to make use of the "params[]" it offers.
Below is an example on how to use sscanf in ZCMD :
PHP код:
// Define two variables for sscanf
new vehicleid, Float: vehiclehealth ;
// Store our data in the variables with sscanf using "params":
if ( sscanf ( params, "if", vehicle, vehiclehealth ) ) {
// If params are incorrect, return a error message here
}
To check if a vehicle ID is valid you do this (inside the same callback you defined the sscanf variables):
PHP код:
if ( ! IsValidVehicleID ( vehicleid ) ) {
// If vehicle is not valid, return error message here
}
Take a look at these wiki posts for more information (as you are using your specifiers incorrectly):
https://sampwiki.blast.hk/wiki/Control_Structures#Operators
https://sampwiki.blast.hk/wiki/Fast_Commands#Data_types
And the functions that do what you want to do:
https://sampwiki.blast.hk/wiki/IsValidVehicle
https://sampwiki.blast.hk/wiki/SetVehicleHealth
For your error, read the big yellow box at the "IsValidVehicle" wiki page.