const string [+REP]
#1

Hey how can I create a const string for playerid, because I want it so when I do /givecarkeys it'll change the const string only for this specific playerid to another value.
How can I do it?

When I try to do this:
PHP код:
new const Keys[MAX_PLAYERS] = 0;
CMD:givecarkeys(playeridparams[])
{
        new 
pididmsg[128];
        if(
sscanf(params"ud"pidid)) return SendClientMessage(playeridCOLOR_GREY"USAGE: /givecarkeys [player] [vehicleid]");
        if(!
IsPlayerConnected(pid)) return SendClientMessage(playeridCOLOR_RED"Invalid player!");
        if(!
IsValidVehicle(id)) return SendClientMessage(playeridCOLOR_RED"Invalid vehicleid!");
        if(
GetPlayerVehicleAccess(playeridid) < 1)
                return 
SendClientMessage(playeridCOLOR_RED"You are not the owner of this vehicle!");
        if(!
PlayerToPlayer(playeridpid10.0)) return SendClientMessage(playeridCOLOR_RED"Player is too far!");
        
SetPVarInt(pid"CarKeys"id);
        
GetPlayerVehicleAccess(playeridid 2);
        
Keys[playerid] = 1;
        
format(msgsizeof(msg), "You have given your car keys to %s (%d)"PlayerName(pid), pid);
        
SendClientMessage(playeridCOLOR_WHITEmsg);
        
format(msgsizeof(msg), "%s (%d) has given you car keys"PlayerName(playerid), playerid);
        
SendClientMessage(pidCOLOR_WHITEmsg);
        return 
1;

I get the errors:
PHP код:
C:\Documents and Settings\user\My Documents\Downloads\avs.pwn(1505) : error 022must be lvalue (non-constant)
C:\Documents and Settings\user\My Documents\Downloads\avs.pwn(1505) : warning 215expression has no effect 
On the line:
PHP код:
        Keys[playerid] = 1
Reply
#2

Try just using


pawn Код:
new Keys[MAX_PLAYERS];
Reply
#3

You also can't modify const values. They are called constants for a reason (you can't change the value after initialization).

Your basically trying to do this.

pawn Код:
0 = 1;
Which will give the exact same error.
Reply
#4

Okay I tried it with new Keys [MAX_PLAYERS] [MAX_VEHICLES]; but now it doesn't save the variable after I re-enter the game, I /givecarkeys and it works then I re-log and the variable is back to 0.
How can I make it stay at 1?
Reply
#5

You must implement it to you saving system
Reply
#6

I don't have any.. what is the easiest?
Reply
#7

Will +REP the one who'll help me
Reply
#8

Help
Reply
#9

Stop bumping your thread please. It's not saving when you re-enter the server because you don't save it (to file) and load the data when you connect. You will need to create an ini file or use SQL to save the data. Then when you enter the server load the data you have saved into said variable.

There are quite a few good tutorials in the tutorial section about saving data to files.
Reply
#10

What's bettter SQL or INI?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)