What's wrong with this CMD? - 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: What's wrong with this CMD? (
/showthread.php?tid=571399)
What's wrong with this CMD? -
lwilson - 18.04.2015
Код:
CMD:registervehicle(playerid, params[])
{
new vehicleid;
foreach(Player, i)
{
if(i == playerid)
{
for(new d=0; d<MAX_PLAYERVEHICLES; d++)
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, CarDealershipInfo[d][cdEntranceX], CarDealershipInfo[d][cdEntranceY], CarDealershipInfo[d][cdEntranceZ]))
{
if(GetPlayerCash(playerid) >= 500)
{
if(PlayerVehicleInfo[i][d][pvId] == vehicleid)
{
if(PlayerVehicleInfo[i][d][pvPlate] == 0)
{
new string[128];
new randplate = 5000000 + random(999999);//minimum 5000000 max 999999
PlayerVehicleInfo[i][d][pvPlate] = randplate;
format(string, sizeof(string), "You registered this vehicle, vehicle's plate is %d.", randplate);
SendClientMessageEx(playerid, COLOR_GRAD4, string);
SendClientMessageEx(playerid, COLOR_GRAD4, "Relog or park your car, to see the vehicle's plate.");
GivePlayerCash(playerid, -500);
}
else
{
SendClientMessageEx(playerid, COLOR_GRAD4, "This vehicle is already registered.");
}
}
else
{
SendClientMessageEx(playerid, COLOR_GRAD4, "This is vehicle is not yours.");
}
}
else
{
SendClientMessageEx(playerid, COLOR_GRAD4, "You need $500 to be able to register this vehicle.");
}
}
else
{
SendClientMessageEx(playerid, COLOR_GRAD4, "You're not near any vehicle dealership.");
}
}
else
{
SendClientMessageEx(playerid, COLOR_GRAD4, "You need to be on the driver's seat to be able to register this vehicle.");
}
}
}
}
return 1;
}
Command is not working Even I'm inside my own vehicle, I'm the driver, I got 500, and I'm 3.0 near a Dealership.
+ Elses are spamming their SendClientMessagesEx.
Help!
Re: What's wrong with this CMD? -
ball - 18.04.2015
You have a return inside a foreach loop - "return" stops code, so first step is removing this return. Also sometimes you are using parameter "i" and sometimes parameter "playerid", for what is that foreach loop?
Re: What's wrong with this CMD? -
lwilson - 18.04.2015
Indentation is fixed, but problem is still not fixed.
Re: What's wrong with this CMD? -
Jefff - 18.04.2015
pawn Код:
GetCarDealershipID(playerid)
{
for(new d=0; d<MAX_PLAYERVEHICLES; d++)
if(IsPlayerInRangeOfPoint(playerid, 3.0, CarDealershipInfo[d][cdEntranceX], CarDealershipInfo[d][cdEntranceY], CarDealershipInfo[d][cdEntranceZ]))
return d;
return -1;
}
CMD:registervehicle(playerid, params[])
{
if(!IsPlayerInAnyVehicle(playerid) || GetPlayerState(playerid) != PLAYER_STATE_DRIVER) SendClientMessageEx(playerid, COLOR_GRAD4, "You need to be on the driver's seat to be able to register this vehicle.");
else if(GetPlayerCash(playerid) < 500) SendClientMessageEx(playerid, COLOR_GRAD4, "You need $500 to be able to register this vehicle.");
else{
new ID = GetCarDealershipID(playerid);
new vehicleid = GetPlayerVehicleID(playerid);
if(ID < 0) SendClientMessageEx(playerid, COLOR_GRAD4, "You're not near any vehicle dealership.");
else if(PlayerVehicleInfo[playerid][ID][pvId] != vehicleid) SendClientMessageEx(playerid, COLOR_GRAD4, "This vehicle is not yours.");
else if(PlayerVehicleInfo[playerid][ID][pvPlate] != 0) SendClientMessageEx(playerid, COLOR_GRAD4, "This vehicle is already registered.");
else{
new string[128];
new randplate = 5000000 + random(999999);//minimum 5000000 max 999999
PlayerVehicleInfo[playerid][ID][pvPlate] = randplate;
format(string, sizeof(string), "You registered this vehicle, vehicle's plate is %d.", randplate);
SendClientMessageEx(playerid, COLOR_GRAD4, string);
SendClientMessageEx(playerid, COLOR_GRAD4, "Relog or park your car, to see the vehicle's plate.");
GivePlayerCash(playerid, -500);
}
}
return 1;
}