Players in the specific world -
ixesas - 04.10.2013
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?
Re: Players in the specific world -
Dragonsaurus - 04.10.2013
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;
}
Re: Players in the specific world -
ixesas - 04.10.2013
Thanks, that's exactly what i needed. +rep )
Re: Players in the specific world -
ixesas - 04.10.2013
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.
Re: Players in the specific world -
Dragonsaurus - 04.10.2013
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);
Re: Players in the specific world -
ixesas - 04.10.2013
Getting errors on:
PHP код:
stock SetPlayerVirtualWorld(playerid, worldid)
PHP код:
error 001: expected token: "-identifier-", but found "("
and getting error on:
PHP код:
return SetPlayerVirtualWorld(playerid, worldid);
PHP код:
error 010: invalid function or declaration
Re: Players in the specific world -
Konstantinos - 04.10.2013
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.
Re: Players in the specific world -
Dragonsaurus - 04.10.2013
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
Re: Players in the specific world -
ixesas - 04.10.2013
Script seems good, but in game when I change virtual world into 1, i get weird numbers in dialog
Re: Players in the specific world -
Dragonsaurus - 04.10.2013
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;
}