SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 30/08/2015, 06:23 PM   #1
Zonoya
Gangsta
 
Zonoya's Avatar
 
Join Date: Jul 2011
Location: Am I in Rio de Janeiro or the Amazon, you tell me?
Posts: 664
Reputation: 19
Default Genuine Confusion

I am genuinely baffled about how I'd go about doing this in my code, I have the code below, for displaying a dialog for the cars the player owns:

Code:
VehicleMenu(playerid)
{
	new str[500], cars = 0;
	for(new i = 0; i < sizeof(vInfo); i++)
	{
	    if(vInfo[i][vOwnerID] == pInfo[playerid][ID])
	    {
	        if(IsAnyPlayerInVehicle(vInfo[i][vCarID]) == 1) format(str, sizeof(str), "%s\n(%d): %s (In Use)", str, cars, vInfo[i][vName]);
	        else format(str, sizeof(str), "%s\n(%d): %s", str, cars, vInfo[i][vName]);
	        cars++;
	    }
	}
	if(cars == 0) SPD(playerid, dCars, DSM, "Vehicles", "You currently own no cars!", "Close", "");
	else SPD(playerid, dCars, DSL, "Vehicles", str, "Close", "");
}
(Apologies for any problems with indentation shown here, just because I copied it from my code.)

The issue I'm having, is not a 'code' syntax issue per se, I'm trying to reference each vehicle, but the problem I have, is that the player can own a LOT of vehicles (in excess of 10-20, even up to 100) the vehicles display fine on the menu from my knowledge on the matter, but because it's all procedural, how would I go about referencing any list items here? since I have no solid ones, but since all the basic formatting would be identical, would I do something like this?

Code:
switch(listitem)
{
    case 1..100:
    {
        // Code here
    }
}
I'm not entirely sure, I just need some guidance here.

The second question I have, is actually to do with the vehicles themselves, if that switch method IS the right way, how on Earth do I go about referencing the correct vehicle? This is my vehicle enumerator:

Code:
enum vData
{
	vID, // The vehicle ID ingame for reference in the script
	vCarID, // The vehicle ID ingame for reference in the script
	vModel, // The vehicle's model
	vName[60], // The vehicle's name
	vOwner[24], // Who owns the vehicle?
	vOwnerID, // What's the ID of the owner?
	Float:vLoc[4], // The 4 positions of the vehicle (X Y Z A)
	vCol1, // Car color 1
	vCol2, // Car color 2
	Text3D:vtextid,
	bool:vLocked
}
new vInfo[MAX_VEHICLES][vData]; // Variable for referencing the enumerator above
I would normally loop through all the vehicles until I found the one that matched the vehicle the player was in, and make sure they owned it, since the player has to be in the vehicle to do most other commands, but for this command, I can't really do that, since the player is rarely going to be in the cars they're looking at on the list, and the player can own multiple cars, the vID is more for the mysql database to uniquely reference each vehicle, and don't represent the vehicle ID for the player, and thus, I don't know how I'd go about doing this.

Now, don't get me wrong here. I don't want it done for me, not in the slightest, I just want some guidance.

Any help would be handy,
Thanks,
Zonoya.
__________________
Code:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success) //If the password was incorrect
    {
        printf("FAILED RCON LOGIN BY IP %s USING PASSWORD %s",ip, password);
        new pip[16];
        for(new i=0; i<MAX_PLAYERS; i++) //Loop through all players
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
            {
                SendClientMessage(i, 0xFFFFFFFF, "Wrong Password. Bye!"); //Send a message
                Ban(i); //They are now banned.
            }
        }
    }
    return 1;
}
Zonoya is offline   Reply With Quote
Old 31/08/2015, 05:20 PM   #2
Zonoya
Gangsta
 
Zonoya's Avatar
 
Join Date: Jul 2011
Location: Am I in Rio de Janeiro or the Amazon, you tell me?
Posts: 664
Reputation: 19
Default Re: Genuine Confusion

Apologies for the bump, but some help with this issue would be greatly appreciated.
__________________
Code:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success) //If the password was incorrect
    {
        printf("FAILED RCON LOGIN BY IP %s USING PASSWORD %s",ip, password);
        new pip[16];
        for(new i=0; i<MAX_PLAYERS; i++) //Loop through all players
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
            {
                SendClientMessage(i, 0xFFFFFFFF, "Wrong Password. Bye!"); //Send a message
                Ban(i); //They are now banned.
            }
        }
    }
    return 1;
}
Zonoya is offline   Reply With Quote
Old 31/08/2015, 05:53 PM   #3
Marricio
Gangsta
 
Join Date: Dec 2010
Posts: 718
Reputation: 96
Default Re: Genuine Confusion

Well, that is pretty easy. You just have to create a multi dimensional array storing the vehicle ID for each listitem.

Some theory code here:
Code:
new DialogInfo[MAX_PLAYERS][100];

new count;
for( new i; I!=MAX_VEHICLES;i++)
{
//check if is owned by the player
DialogInfo[playerid][count] = i;
count++;
}

//on dialog response
new vehicleid = DialogInfo[playerid][listitem];
Marricio is offline   Reply With Quote
Old 31/08/2015, 06:05 PM   #4
Zonoya
Gangsta
 
Zonoya's Avatar
 
Join Date: Jul 2011
Location: Am I in Rio de Janeiro or the Amazon, you tell me?
Posts: 664
Reputation: 19
Default Re: Genuine Confusion

Oh.... That's.... Really God damn simple actually, I can't believe I didn't think of that.

Thank you.

Oh, another question, though...

With the:

case 1..100

thing, is it possible to do like:

case 1..pInfo[playerid][CarSlots]

or something similar? That particular variable stores how many vehicles the player has, which would be all that shows on the dialog.

If not, that's fine, I can work with it, I'm just wondering.
__________________
Code:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success) //If the password was incorrect
    {
        printf("FAILED RCON LOGIN BY IP %s USING PASSWORD %s",ip, password);
        new pip[16];
        for(new i=0; i<MAX_PLAYERS; i++) //Loop through all players
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
            {
                SendClientMessage(i, 0xFFFFFFFF, "Wrong Password. Bye!"); //Send a message
                Ban(i); //They are now banned.
            }
        }
    }
    return 1;
}
Zonoya is offline   Reply With Quote
Old 31/08/2015, 06:12 PM   #5
Marricio
Gangsta
 
Join Date: Dec 2010
Posts: 718
Reputation: 96
Default Re: Genuine Confusion

Well, you wouldn't need to use a switch or check any variable to obtain the correct ID as you're already obtaining it from the variable. However, it is not possible to do it using switch.

Do this:
Code:
if( variable >= 1 && variable <= pInfo[playerid][CarSlots] )
Change the "variable" name accordingly.
Marricio is offline   Reply With Quote
Old 31/08/2015, 06:14 PM   #6
Zonoya
Gangsta
 
Zonoya's Avatar
 
Join Date: Jul 2011
Location: Am I in Rio de Janeiro or the Amazon, you tell me?
Posts: 664
Reputation: 19
Default Re: Genuine Confusion

Hmm, good to know, thank you for the help.
__________________
Code:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success) //If the password was incorrect
    {
        printf("FAILED RCON LOGIN BY IP %s USING PASSWORD %s",ip, password);
        new pip[16];
        for(new i=0; i<MAX_PLAYERS; i++) //Loop through all players
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
            {
                SendClientMessage(i, 0xFFFFFFFF, "Wrong Password. Bye!"); //Send a message
                Ban(i); //They are now banned.
            }
        }
    }
    return 1;
}
Zonoya 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
More Genuine Color Farshid1994 Scripting Help 2 20/06/2013 03:16 PM
[Genuine Roleplay Project] Joshswag Scripting Help 3 05/02/2012 07:50 AM
Little Confusion iRemix Help Archive 5 30/01/2011 10:49 PM


All times are GMT. The time now is 01:27 AM.


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