SetPVarInt & GetPVarInt
#1

Okay, I have a question. Well, more like a problem, and I'm not sure if its me.

I'm using SetPVarInt & GetPVarInt etc etc for skin saving while connected to server;

Wiki;
* https://sampwiki.blast.hk/wiki/SetPVarInt
* https://sampwiki.blast.hk/wiki/GetPVarInt - etc etc ...

" The command "
pawn Код:
dcmd_vskin(playerid, params[])
{
    new skin = strval(params);
    if(IsPlayerInAnyVehicle(playerid))                                  return SendErrorMessage(playerid, "You can't use this command while in a vehicle.");
    if(!strlen(params))                                                 return SendSyntaxMessage(playerid, "/vskin [skin id]");
    if(skin < MIN_SKIN_ID || skin > MAX_SKIN_ID || IsInvalidSkin(skin)) return SendErrorMessage(playerid, "Invalid skin ID.");
    if(skin == 211 || skin == 217 || skin == 165 || skin == 147)                       return SendErrorMessage(playerid, "You can't use that skin. Choose another one.");

       
    SetPlayerSkin(playerid, skin);

    SetPVarInt(playerid, "PlayerSkin", skin); // #This is where the Var is placed#

    return 1;
}
this is when its used; (all the way at the end)
[ edit ]
This is placed on: public OnPlayerSpawn(playerid)

pawn Код:
// Set player skin to users (staff or player)
    if(GetPVarInt(playerid, "PlayerSkin"))
    {
        SetPlayerSkin(playerid, GetPVarInt(playerid, "PlayerSkin")); // # Universal #
    }
now, when i placed this coding it seemed to work for a bit, now its not.

Is there another better way of doing this? ...
(I'm trying to avoid using timers to get GetPVarInt(playerid, "PlayerSkin") then set it- if you understand what i mean)
Reply
#2

Actually, you are not explaining your problem. You just seem to show us your code which will not help you.

But check this...
Код:
if(GetPVarInt(playerid, "PlayerSkin"))
    {
        SetPlayerSkin(playerid, GetPVarInt(playerid, "PlayerSkin")); // # Universal #
    }
When you use the above code in OnPlayerSpawn, the player will spawn with skin id 0. Because, the player would not have chosen his skin using the /vskin at spawning immediately after class selection. Is that your problem, then you must first check if the player has chosen his skin using /vskin or prompt him to do that before spawning.

If not, please specify the problem.
Reply
#3

So you need a better and efficient way? Idk, this seems good to me, but you can use normal variables instead of PVars.
Reply
#4

Quote:
Originally Posted by Mean
Посмотреть сообщение
So you need a better and efficient way? Idk, this seems good to me, but you can use normal variables instead of PVars.
its not working! thats my problem...


Quote:
Originally Posted by deather
Посмотреть сообщение
Actually, you are not explaining your problem. You just seem to show us your code which will not help you.

But check this...
Код:
if(GetPVarInt(playerid, "PlayerSkin"))
    {
        SetPlayerSkin(playerid, GetPVarInt(playerid, "PlayerSkin")); // # Universal #
    }
When you use the above code in OnPlayerSpawn, the player will spawn with skin id 0. Because, the player would not have chosen his skin using the /vskin at spawning immediately after class selection. Is that your problem, then you must first check if the player has chosen his skin using /vskin or prompt him to do that before spawning.

If not, please specify the problem.
....

Player will not spawn with ID 0 ? why? if when the command is made the skin should be already set
(the code is there ^)


the code WAS working, and now its not, so - that doesn't make any sense (on why),
if it worked the first time,
why its no longer working, trying to figure out what the problem is.

when the command is done, no matter how the command is set, its already set when the command is used
but when its called on spawn - it no longer works, when they die or get killed the skin doesn't get set the way its supposed to be.

It did work once, i made NO changes to it.
and now its not working.
Reply
#5

Use SetSpawnInfo (https://sampwiki.blast.hk/wiki/SetSpawnInfo) instead of that bit of code you're using inside OnPlayerSpawn. It is far more reliable and doesn't require the frequent resetting of the player's skin like you're trying to do in OnPlayerSpawn. I encountered similar oddities long ago and ended up resorting to this.

Your Dcmd for vskin looks logically and syntactically correct though, remember, anytime someone changes their skin using that command, you have to reset their SetSpawnInfo settings or they will spawn using the old skin.

EDIT: Also, don't use it onplayerspawn, use it inside onplayerrequestskin and the skin command.
Reply
#6

oh... I think... i know what you mean !
had to re-read this like 100 times, but i think i get it.

i'll try (around that - the spawn info issue) it and see.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)