SA-MP Forums

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

 
 
Thread Tools Display Modes
Old 05/04/2010, 09:00 AM   #1
Dark_Kostas
Gangsta
 
Join Date: Dec 2007
Location: Greece, Athens
Posts: 542
Reputation: 14
Default Looping Pvars

How can i create something like that with PVars?(Int)

pawn Code:
for(new i;i<10;i++)
{
    if(i == 0) SetPVarInt(playerid, "Car[i]", 600);
    else if(i == 5) SetPVarInt(playerid, "Car[i]", 560);
    else SetPVarInt(playerid, "Car[i]", 0);
}
for(new i;i<10;i++)
{
    printf("Number %d Value %d", i, GetPVarInt(playerid, "Car[i]"));
}

How can i do something like that? It will print always "0" as it is the Set that will be used. I dont want to do it manually Car1 Car2 up to Car10
__________________
Quote:
Help != Scripting for you.

Give a man a fish he eats for a day, teach a man to fish he eats for a life time.
Dark_Kostas is offline  
Old 05/04/2010, 12:05 PM   #2
Babul
High-roller
 
Babul's Avatar
 
Join Date: Sep 2009
Location: in a cement block
Posts: 1,782
Reputation: 251
Default Re: Looping Pvars

using the SetPVar like this wont work, just format your PVariable string (its name) like u would for accessing a file:
Code:
	format(pvarstring,sizeof(pvarstring),"Car%d",carID);
then you can use that formatted name instead of the "Car[i]" to get being processed in any way:
Code:
	SetPVarInt(playerid,pvarstring,123)
	format(line,sizeof(line),"%s %d\r\n",pvarstring,GetPVarInt(TargetID,pvarstring));
__________________
FireWorks

new sscanf2 custom specifiers available for Download, read the Release Topic
Babul is offline  
Old 05/04/2010, 12:11 PM   #3
biltong
Gangsta
 
Join Date: Jan 2010
Posts: 546
Reputation: 0
Default Re: Looping Pvars

You don't need to make any variables with PVars, so where you use
Code:
Car[i]
is wrong. A simple loop would look like:
pawn Code:
for(new i; i < MAX_PLAYERS; i++)
{
    new string[64];
    format(string, sizeof(string), "Your variable: %i", GetPVarInt(i, "YourVariable");
    SendClientMessage(i, 0xFFFFFFFF, string);
}
__________________
My releases:
[FS]Admin Click - An admin shortcut script. Lots of commands like kick and ban in a few mouse clicks!
[FS]Vehicle Names - Simple script that displays your vehicle's name whenever you enter one.
[GM]Cops 'n Criminals - An unusual TDM.


Not active anymore, PM me if necessary.
biltong is offline  
Old 05/04/2010, 03:46 PM   #4
Dark_Kostas
Gangsta
 
Join Date: Dec 2007
Location: Greece, Athens
Posts: 542
Reputation: 14
Default Re: Looping Pvars

Quote:
Originally Posted by biltong
You don't need to make any variables with PVars, so where you use
Code:
Car[i]
is wrong. A simple loop would look like:
pawn Code:
for(new i; i < MAX_PLAYERS; i++)
{
    new string[64];
    format(string, sizeof(string), "Your variable: %i", GetPVarInt(i, "YourVariable");
    SendClientMessage(i, 0xFFFFFFFF, string);
}
I think you didnt understand what i wanted to do. The loop is not about max_players, but its about Car[Number]
--------------------------------------
Quote:
Originally Posted by Babul
using the SetPVar like this wont work, just format your PVariable string (its name) like u would for accessing a file:
Code:
	format(pvarstring,sizeof(pvarstring),"Car%d",carID);
then you can use that formatted name instead of the "Car[i]" to get being processed in any way:
Code:
	SetPVarInt(playerid,pvarstring,123)
	format(line,sizeof(line),"%s %d\r\n",pvarstring,GetPVarInt(TargetID,pvarstring));
thanks i bet this will work. I was thinking so much time, and it was so simple Thanks again.

EDIT: And yes it worked
__________________
Quote:
Help != Scripting for you.

Give a man a fish he eats for a day, teach a man to fish he eats for a life time.
Dark_Kostas is offline  
Old 06/04/2010, 07:18 AM   #5
Babul
High-roller
 
Babul's Avatar
 
Join Date: Sep 2009
Location: in a cement block
Posts: 1,782
Reputation: 251
Default Re: Looping Pvars

glad to read ^^
i faced the same problem at fiddling around with PVars, it wasnt that hard to figure out that each string can (needs) to be formatted before usage
__________________
FireWorks

new sscanf2 custom specifiers available for Download, read the Release Topic
Babul is offline  
 

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
[SOLVED] to pvars russo666 Help Archive 5 31/05/2010 09:28 PM
Pvars Steven82 Help Archive 0 26/05/2010 08:52 PM
PVars Question(s) XGh0stz Help Archive 0 02/04/2010 08:08 PM
Pvars question? Torran Help Archive 4 26/03/2010 05:53 PM
Pvars... biltong Help Archive 8 26/03/2010 01:31 PM


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


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