SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/02/2019, 10:24 PM   #1
SymonClash
Big Clucker
 
SymonClash's Avatar
 
Join Date: Dec 2018
Posts: 121
Reputation: 8
Default A quick help

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

pawn Code:
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.
SymonClash is offline   Reply With Quote
Old 12/02/2019, 12:00 AM   #2
AhmedMohamed
Huge Clucker
 
AhmedMohamed's Avatar
 
Join Date: Jan 2014
Location: Egypt
Posts: 338
Reputation: 3
Default Re: A quick help

pawn Code:
stock VehicleOwner(vehid, playerid)
{
if(!strcmp(vInfo[vehid][vehOwner], ReturnPlayerName(playerid)))
     return true;
return false;
}
AhmedMohamed is offline   Reply With Quote
Old 12/02/2019, 12:15 AM   #3
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,345
Reputation: 1271
Default Re: A quick help

Quote:
Originally Posted by AhmedMohamed View Post
pawn Code:
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.
Pottus is online now   Reply With Quote
Old 12/02/2019, 12:22 AM   #4
AhmedMohamed
Huge Clucker
 
AhmedMohamed's Avatar
 
Join Date: Jan 2014
Location: Egypt
Posts: 338
Reputation: 3
Default Re: A quick help

I really need the name because the Id is changing every time the playerr connect to the game
AhmedMohamed is offline   Reply With Quote
Old 12/02/2019, 01:05 AM   #5
Thundey
Little Clucker
 
Join Date: Jul 2013
Location: United Kingdom
Posts: 40
Reputation: 1
Default Re: A quick help

Not if u assign a perm ID to each user, then u can actually just store the ID assigned separately.
Thundey is offline   Reply With Quote
Old 12/02/2019, 01:17 AM   #6
SymonClash
Big Clucker
 
SymonClash's Avatar
 
Join Date: Dec 2018
Posts: 121
Reputation: 8
Default Re: A quick help

@AhmedMohamed thanks, but what about the foreach loop?
SymonClash is offline   Reply With Quote
Old 12/02/2019, 01:54 AM   #7
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,699
Reputation: 3226
Default Re: A quick help

You can still use the ID instead of the name - just get the ID from the name when they connect (and log in, I assume you aren't just trusting people not to lie about their name). Also, your original code doesn't make sense. You loop over the vehicles owned by a player and check if they are owned by the player. Why?

Are you trying to do something like this:

pawn Code:
bool:DoesPlayerOwnVehicle(playerid, vehicleid)
{
    foreach (new i : PrivateVehicles[playerid])
    {
        if (i == vehicleid) return true;
    }
    return false;
}

Also note the lack of "stock" AhmedMohamed, you should know better by now.
Y_Less is online now   Reply With Quote
Old 12/02/2019, 02:52 PM   #8
SymonClash
Big Clucker
 
SymonClash's Avatar
 
Join Date: Dec 2018
Posts: 121
Reputation: 8
Default Re: A quick help

Ok thanks.
SymonClash is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick Ans. ManGoe Scripting Help 2 07/12/2014 07:39 AM
Please a quick help about VPS :) TheArcher Everything and Nothing 17 29/09/2012 07:55 AM
Quick Help ThomasCarter Scripting Help 1 16/09/2012 02:17 PM
Quick help Slaykler Scripting Help 0 14/09/2012 03:35 PM
Quick Help Mini` Help Archive 3 24/05/2010 07:22 AM


All times are GMT. The time now is 02:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.