SetPlayerVirtualWorld
#1

Hello, I wanted to make a system where, if you are new, you will be put in a VirtualWorld, but I don't know how to keep changing the number, this is what I've got so far

Code:
new VW = 20;
pawn Code:
public OnPlayerSpawn(playerid)
{
    if (pInfo[playerid][Newbie] == 1)
    {
    new str[128];
    SetPlayerVirtualWorld(playerid, VW + 1);
    format(str, sizeof(str), "You are in VW %d", GetPlayerVirtualWorld(playerid));
    SendClientMessage(playerid, -1, str);
    }
    return 1;
}
can I have some help? thanks
Reply
#2

pawn Code:
// In OnPlayerSpawn
VW++;
SetPlayerVirtualWorld(playerid,VW);
There you go
Reply
#3

SetPlayerVirtualWorld(playerid, playerid + 20);
Reply
#4

pawn Code:
public OnPlayerSpawn(playerid)
{
    if(pInfo[playerid][Newbie] == 1)
    {
        //new str[128]; Why 128? you only need 20-30 max.
        new str[30],vw = GetPlayerVirtualWorld(playerid);
        SetPlayerVirtualWorld(playerid, vw + random(999));
        format(str, sizeof(str), "You are in VW %d.",vw); // Don't call the function GetPlayerVirtualWorld twice, you could call it once and assign it to a variable.
        SendClientMessage(playerid, -1, str);
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by DaniceMcHarley
View Post
pawn Code:
public OnPlayerSpawn(playerid)
{
    if(pInfo[playerid][Newbie] == 1)
    {
        //new str[128]; Why 128? you only need 20-30 max.
        new str[30],vw = GetPlayerVirtualWorld(playerid);
        SetPlayerVirtualWorld(playerid, vw + random(999));
        format(str, sizeof(str), "You are in VW %d.",vw); // Don't call the function GetPlayerVirtualWorld twice, you could call it once and assign it to a variable.
        SendClientMessage(playerid, -1, str);
    }
    return 1;
}
He didn't call he function twice, and you're at one point giving him advice to save processing, but on the other hand you're advicing him to add more processing (random). It doesn't have to be that hard.
Even my code were less efficient than Sjn's since I still had an integer, and his used 'playerid' which is already defined.

The only code he needs is playerid+whateverhewants and nobody else will get the same VW.
Reply
#6

Use a boolean instead of a whole integer number.

Quote:

if(variable) = true, if(!variable) = false

pawn Code:
public OnPlayerSpawn(playerid)
{
    if(pInfo[playerid][Newbie]) SetPlayerVirtualWorld(playerid, playerid);
    return 1;
}
Reply
#7

Quote:
Originally Posted by liquor
View Post
He didn't call he function twice, and you're at one point giving him advice to save processing, but on the other hand you're advicing him to add more processing (random). It doesn't have to be that hard.
Even my code were less efficient than Sjn's since I still had an integer, and his used 'playerid' which is already defined.

The only code he needs is playerid+whateverhewants and nobody else will get the same VW.
Because his code was wrong from the first time. I didn't get him though you might be right because he did not elaborate correctly.
Reply
#8

Thanks for the help guys!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)