SA-MP Forums Archive
A quick help - 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: A quick help (/showthread.php?tid=663814)



A quick help - SymonClash - 11.02.2019

I have this code to check if the vehicle is of the owner:

pawn Код:
foreach(new i : PrivateVehicles[playerid])
{
if(!strcmp(vInfo[i][vehOwner], ReturnPlayerName(playerid)))
//This vehicle is yours
}
}
It works perfectly but i've a "problem". Is there a way to shorten this?

Since i have some vehicle related commands restriced only for vehicle owners, it's damn ugly and stupid write everytime this long code to check it.

I wanna do something like:

if(VehicleOwner(playerid) return "You're owner of this vehicle".

Hope i was clear, thanks.


Re: A quick help - AhmedMohamed - 11.02.2019

pawn Код:
stock VehicleOwner(vehid, playerid)
{
if(!strcmp(vInfo[vehid][vehOwner], ReturnPlayerName(playerid)))
     return true;
return false;
}



Re: A quick help - Pottus - 11.02.2019

Quote:
Originally Posted by AhmedMohamed
Посмотреть сообщение
pawn Код:
stock VehicleOwner(vehid, playerid)
{
if(!strcmp(vInfo[vehid][vehOwner], ReturnPlayerName(playerid)))
     return true;
return false;
}
That is horrible!
Why would you store the name? The ID is fine get the name when you need to.


Re: A quick help - AhmedMohamed - 11.02.2019

I really need the name because the Id is changing every time the playerr connect to the game


Re: A quick help - Thundey - 12.02.2019

Not if u assign a perm ID to each user, then u can actually just store the ID assigned separately.


Re: A quick help - SymonClash - 12.02.2019

@AhmedMohamed thanks, but what about the foreach loop?


Re: A quick help - SymonClash - 12.02.2019

Ok thanks.