Turning a string into an enum variable declaration.
#1

Is it even possible to turn a string into an enum variable declaration? Something like this:

Код:
new string[80];
string="PlayerInfo[playerid][Money]=800";
into

Код:
PlayerInfo[playerid][Money]=800;
What I am trying to do is make a filterscript that has a rcon command to edit a players enum information. But is that even possible?
Reply
#2

Impossible. All human readable data is discarded and replaced with memory addresses upon compilation, the only exception being public functions. This also explains why decompiled scripts use var0 or glob37.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Impossible. All human readable data is discarded and replaced with memory addresses upon compilation, the only exception being public functions. This also explains why decompiled scripts use var0 or glob37.
Thank you for the answer Vince I am glad that there are people like you, who are more intelligent and can help others.
Reply
#4

Sorry for the doublepost, but I wanted for the topic to come up and to ask again if it is really impossible? I think there is a way with PVars.

EDIT: I think I did not say the main idea clearly, so you misunderstood me Vince. What I am trying to do is make a filterscript that has a rcon command and the server owner could use the rcon command inside the server console to edit players information. For example:

/player ID Money=600 XP=10 AdminLevel=2

And I think it is possible with PVars.
Reply
#5

No it is not,
However you can do something like this maybe :
PHP код:
CMD:editstats(playerid, params[])
{
    if(!
IsPlayerAdmin(playerid))return SendClientMessage(playerid, 0xFF0000FF, "You are not authorized to use this command");
    new 
tid, stat[10], val;
    if(
sscanf(params, "us[10]d" tid, stat, va))return SendClientMessage(playerid, 0xFF0000FF, "Usage /setstat [target player] [Stat to set] [Value]");
    if(!
IsPlayerConnected(tid))return SendClientMessage(playerid, 0xFF0000FF, "Invalid playerid!");
    if(!
strcmp(params, "money", true))
    {
        
PlayerInfo[tid][Money] = val;
        
SendClientMessage(playerid, 0x00cc00FF, "Player Stats changed!");
    }
    else if(!
strcmp(params, "cash", true))
    {
        
PlayerInfo[tid][Cash] = val;
        
SendClientMessage(playerid, 0x00cc00FF, "Player Stats changed!");
    }
    else 
SendClientMessage(playerid, 0xFF0000FF, "Invalid Stat!");
    return 
1;
} 
Reply
#6

It is possible only with PVars, here's an example snippet:
pawn Код:
CMD:setvar(playerid, params[]) {

    if(!IsPlayerAdmin(playerid)) return 0;
    new
        temp_Player,
        temp_Type,
        temp_pVar[32],
        temp_Value[60]
    ;
   
    if(sscanf(params, "rcs[32]s[32]", temp_Player, temp_Type, temp_pVar)) {
   
        SendClientMessage(playerid, 0xFF0000FF, "USAGE : /setvar [playerid] [Type] [pVar] [Value]");
        return SendClientMessage(playerid, 0xFF0000FF, "Type : i = Integer, s = String, f = Float");
    }
    if(!IsPlayerConnected(temp_Player))
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR : Player is not connected!");

    switch(temp_Type) {
   
        case 'i' : SetPVarInt(temp_Player, temp_pVar, strval(temp_Value));
        case 'f' : SetPVarFloat(temp_Player, temp_pVar, floatstr(temp_Value));
        case 's' : SetPVarString(temp_Player, temp_pVar, temp_Value);
        default : return SendClientMessage(playerid, 0xFF0000FF, "ERROR : Invalid type!");
    }
    format(temp_Value, sizeof(temp_Value), "Player var : %s updated!", temp_pVar);
    return SendClientMessage(playerid, -1, temp_Value);
}
Reply
#7

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
It is possible only with PVars, here's an example snippet:
pawn Код:
CMD:setvar(playerid, params[]) {

    if(!IsPlayerAdmin(playerid)) return 0;
    new
        temp_Player,
        temp_Type,
        temp_pVar[32],
        temp_Value[60]
    ;
   
    if(sscanf(params, "rcs[32]s[32]", temp_Player, temp_Type, temp_pVar)) {
   
        SendClientMessage(playerid, 0xFF0000FF, "USAGE : /setvar [playerid] [Type] [pVar] [Value]");
        return SendClientMessage(playerid, 0xFF0000FF, "Type : i = Integer, s = String, f = Float");
    }
    if(!IsPlayerConnected(temp_Player))
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR : Player is not connected!");

    switch(temp_Type) {
   
        case 'i' : SetPVarInt(temp_Player, temp_pVar, strval(temp_Value));
        case 'f' : SetPVarFloat(temp_Player, temp_pVar, floatstr(temp_Value));
        case 's' : SetPVarString(temp_Player, temp_pVar, temp_Value);
        default : return SendClientMessage(playerid, 0xFF0000FF, "ERROR : Invalid type!");
    }
    format(temp_Value, sizeof(temp_Value), "Player var : %s updated!", temp_pVar);
    return SendClientMessage(playerid, -1, temp_Value);
}
And by my logic, it's actually possible to transfer the PVar value to the gamemodes players enum variables. Ofcourse it's stupid to use enums and PVars at the same time, but if you really need it, it's the only way it works. I think I got the command to work. I just need to test it. I made the command more complex than yours Lordzy, as I made the command to be used easier, as I gave the example. At first I made the command in zcmd, but then I got the "undefined symbol cmd_..." error and then I remembered that zcmd commands are like functions, so you cannot put them in any callbacks, which in my case I need the command in OnRconCommand public function. I just need some more time to test the command and fully finish it. I will post later what I ended up with.
Reply
#8

It is possible to put zcmd commands under callbacks, if you want to ignore the parameter warnings, you've to just fill them.
pawn Код:
public OnCallback(playerid) {

    cmd_setvar(playerid, "0 i Money 5000");
    return 1;
}
You can try the 'e' specifier of sscanf to split and store data into your enumerator.
Reply


Forum Jump:


Users browsing this thread: