Players in the specific world
#1

Hey. I'm making virtual worlds system right now, and need some advice for showing how many players is in specific world at this moment.
Should i use World1++, World2++ etc. when some player join into world1 or world2?
Reply
#2

pawn Код:
#include <zcmd>  // You need zcmd for this command.

CMD:playerworlds(playerid, params[])
{
    new World[100];  // Change the 100 to the number of virtual world you use.
    new string[128];  // You can change 128 and make it bigger size if you use many virtual worlds.
    for(new i = 0; i < GetMaxPlayers(); i++)
    {
        if(!IsPlayerConnected(i)) continue;
        new vw = GetPlayerVirtualWorld(i);
        World[vw]++;
    }
    for(new i = 0; i < sizeof(World); i++)
    {
        format(string, sizeof(string), "%s\nWorld: %d\t\tPlayers: %d", string, i, World[i]);
    }
    ShowPlayerDialog(playerid, 1234, DIALOG_STYLE_LIST, "Players in specific Virtual World", string, "Close", "");
    // I used dialog style LIST becuase many worlds will be shown non-esthetically in MSGBOX.
    return 1;
}
Reply
#3

Thanks, that's exactly what i needed. +rep )
Reply
#4

BUMP.
Is there any function, that checks "OnPlayerChangeVirtualWorld"? I mean, when player changes virtual world, i will use World[vw]--; to remove 1 player from the world he was before.
Reply
#5

pawn Код:
//First remove the World[100]; from the command and place it on top of your script
new World[100];

// Put this under any public callback (Not inside)
public OnPlayerVirtualWorldChange(playerid, oldworldid, newworldid)
{
    World[newworldid]++;
    World[oldworldid]--;
    return 1;
}

// The code below at the end of your script.
stock SetPlayerVirtualWorld(playerid, worldid)
{
    CallLocalFunction("OnPlayerVirtualWorldChange", "ddd", playerid, GetPlayerVirtualWorld(playerid), worldid);
    return SetPlayerVirtualWorld(playerid, worldid);
}
#if defined _ALS_SetPlayerVirtualWorld
    #undef SetPlayerVirtualWorld
#else
    #define _ALS_SetPlayerVirtualWorld
#endif
#define SetPlayerVirtualWorld _ALS_SetPlayerVirtualWorld
forward OnPlayerVirtualWorldChange(playerid, oldworldid, newworldid);
Reply
#6

Getting errors on:
PHP код:
stock SetPlayerVirtualWorld(playeridworldid
PHP код:
error 001expected token"-identifier-"but found "(" 
and getting error on:
PHP код:
return SetPlayerVirtualWorld(playeridworldid); 
PHP код:
error 010invalid function or declaration 
Reply
#7

Quote:
Originally Posted by Dragonsaurus
Посмотреть сообщение
pawn Код:
//First remove the World[100]; from the command and place it on top of your script
new World[100];

// Put this under any public callback (Not inside)
public OnPlayerVirtualWorldChange(playerid, oldworldid, newworldid)
{
    World[newworldid]++;
    World[oldworldid]--;
    return 1;
}

// The code below at the end of your script.
stock SetPlayerVirtualWorld(playerid, worldid)
{
    CallLocalFunction("OnPlayerVirtualWorldChange", "ddd", playerid, GetPlayerVirtualWorld(playerid), worldid);
    return SetPlayerVirtualWorld(playerid, worldid);
}
#if defined _ALS_SetPlayerVirtualWorld
    #undef SetPlayerVirtualWorld
#else
    #define _ALS_SetPlayerVirtualWorld
#endif
#define SetPlayerVirtualWorld _ALS_SetPlayerVirtualWorld
forward OnPlayerVirtualWorldChange(playerid, oldworldid, newworldid);
This is not how hooking works.

https://sampforum.blast.hk/showthread.php?tid=441293

Moreover the OnPlayerVirtualWorldChange must be called when the virtual world is different because if the player move from the a virtual world to the same virtual world, it will call OnPlayerVirtualWorldChange. However, the virtual world was NOT changed.
Reply
#8

Oops, forgot something. Here:
pawn Код:
stock Call_SetPlayerVirtualWorld(playerid, worldid)
{
    new vw = GetPlayerVirtualWorld(playerid);
    if(vw != worldid) CallLocalFunction("OnPlayerVirtualWorldChange", "ddd", playerid, vw, worldid);
    return SetPlayerVirtualWorld(playerid, worldid);
}
#if defined _ALS_SetPlayerVirtualWorld
    #undef SetPlayerVirtualWorld
#else
    #define _ALS_SetPlayerVirtualWorld
#endif
#define SetPlayerVirtualWorld Call_SetPlayerVirtualWorld
forward OnPlayerVirtualWorldChange(playerid, oldworldid, newworldid);
Edit: @Konstantinos: Yes, I know how it works, I just was in a hurry. If I wouldn't know, I would not be able to write my include
Reply
#9

Script seems good, but in game when I change virtual world into 1, i get weird numbers in dialog
Reply
#10

That worked fine with me, I tried to change my world, reset it and no such bug.
Hmm, well, do you use any kind of /setallworld command?

Edit: Also do not forget this:
pawn Код:
public OnPlayerConnect(playerid)
{
    World[GetPlayerVirtualWorld(playerid)]++;
    return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
    World[GetPlayerVirtualWorld(playerid)]--;
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)