sscanf(2.0) and 2 commands in one [Read inside..] - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: sscanf(2.0) and 2 commands in one [Read inside..] (
/showthread.php?tid=144377)
sscanf(2.0) and 2 commands in one [Read inside..] -
dcmd_crash - 26.04.2010
Okay, so I have several of these commands that will do something without a parameter (example, fix the players car who uses the command) or if they enter a playerID it will fix their car .. please see example below.
pawn Код:
CMD:vr(playerid,params[])
{
new player1, playername[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[128];
if(isnull(params))
{
if(PlayerInfo[playerid][Level] >= 2)
{
if(IsPlayerInAnyVehicle(playerid))
{
RepairVehicle(GetPlayerVehicleID(playerid));//SetVehicleHealth(GetPlayerVehicleID(playerid),1250.0);
return SendClientMessage(playerid,MANAGEMENT,"Vehicle Fixed");
} else return SendClientMessage(playerid,red,"Error: You are not in a vehicle");
} else return 0;
}
else if(!isnull(params) && sscanf(params, "u", player1))
{
if(PlayerInfo[playerid][Level] >= 2)
{
if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID && player1 != playerid)
{
GetPlayerName(player1, playername, sizeof(playername)); GetPlayerName(playerid, adminname, sizeof(adminname));
format(string,sizeof(string),"*** %s has repaired your vehicle",adminname); SendClientMessage(player1,MANAGEMENT,string);
if(IsPlayerInAnyVehicle(player1))
{
SetVehicleHealth(GetPlayerVehicleID(player1),1000.0);
new car = GetVehicleModel(GetPlayerVehicleID(player1));
format(string,sizeof(string),"*** You have repaired %s's %s", playername, car);
return SendClientMessage(playerid,MANAGEMENT,string);
} else return SendClientMessage(playerid,red,"Error: Player is not in a vehicle");
} else return SendClientMessage(playerid, red, "Player is not connected or is yourself");
} else return 0;
}
return 1;
}
Thing is, when I enter a playerid it does nothing. At first I thought it was like, just not sending the message or something, but on closer inspection it doesn't execute the command at all. Am I doing something wrong?
Thanks for you help
Re: sscanf(2.0) and 2 commands in one [Read inside..] -
smeti - 27.04.2010
Try:
pawn Код:
CMD:vr(playerid, params[]) // Usage /vr [playerid/name] health
{
new
string[128];
if(PlayerInfo[playerid][Level] >= 2)
{
if(isnull(params))
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, red, "Error: You are not in a vehicle.");
RepairVehicle(GetPlayerVehicleID(playerid)); // SetVehicleHealth(GetPlayerVehicleID(playerid),1250.0);
PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
SendClientMessage(playerid, MANAGEMENT, "Vehicle Fixed");
} else {
new
player1,
Car_health;
sscanf(params, "uD(1000)", player1, Car_health); // Use sscanf 2.0
if(player1 == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "Player is not connected or is yourself.");
if(!IsPlayerInAnyVehicle(player1)) return SendClientMessage(playerid, red, "Error: Player is not in a vehicle.");
new
Vehicle_ID = GetPlayerVehicleID(player1);
if(Car_health == 1000) { RepairVehicle(Vehicle_ID); } else { SetVehicleHealth(Vehicle_ID, Car_health); }
PlayerPlaySound(player1, 1133, 0.0, 0.0, 0.0);
format(string, sizeof (string), "*** %s has repaired your vehicle", GetName(playerid));
SendClientMessage(player1, MANAGEMENT, string);
if(playerid != player1)
{
format(string, sizeof (string), "*** You have repaired %s's Vehicle_Model %d", GetName(player1), GetVehicleModel(Vehicle_ID));
SendClientMessage(playerid, MANAGEMENT, string);
}
}
} else return 0;
return 1;
}
stock GetName(Check_playerid)
{
new
Check_Player_Name[MAX_PLAYER_NAME] = "No Name XD";
GetPlayerName(Check_playerid, Check_Player_Name, sizeof(Check_Player_Name));
return Check_Player_Name;
}
Re: sscanf(2.0) and 2 commands in one [Read inside..] -
dcmd_crash - 27.04.2010
I do use 2.0 xD! Thanks for the reply, I've just woke up, going to open PAWNO and test it.
EDIT: Thanks, it works fine now!