setcarhp command
#1

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
Reply
#2

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 vehicleidFloatvehiclehealth ;
// Store our data in the variables with sscanf using "params":
if ( sscanf params"if"vehiclevehiclehealth ) ) {
    
// 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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)