SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 04/10/2013, 11:28 AM   #1
ixesas
Big Clucker
 
ixesas's Avatar
 
Join Date: Feb 2011
Location: Lithuanian, Kaunas
Posts: 127
Reputation: 11
Default Players in the specific world

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?
ixesas is offline   Reply With Quote
Old 04/10/2013, 11:46 AM   #2
Dragonsaurus
Gangsta
 
Dragonsaurus's Avatar
 
Join Date: Apr 2013
Location: Albania | Vlora
Posts: 509
Reputation: 52
Default Re: Players in the specific world

Code:
#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;
}
Dragonsaurus is offline   Reply With Quote
Old 04/10/2013, 11:51 AM   #3
ixesas
Big Clucker
 
ixesas's Avatar
 
Join Date: Feb 2011
Location: Lithuanian, Kaunas
Posts: 127
Reputation: 11
Default Re: Players in the specific world

Thanks, that's exactly what i needed. +rep )
ixesas is offline   Reply With Quote
Old 04/10/2013, 12:20 PM   #4
ixesas
Big Clucker
 
ixesas's Avatar
 
Join Date: Feb 2011
Location: Lithuanian, Kaunas
Posts: 127
Reputation: 11
Default Re: Players in the specific world

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.
ixesas is offline   Reply With Quote
Old 04/10/2013, 01:05 PM   #5
Dragonsaurus
Gangsta
 
Dragonsaurus's Avatar
 
Join Date: Apr 2013
Location: Albania | Vlora
Posts: 509
Reputation: 52
Default Re: Players in the specific world

Code:
//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);
Dragonsaurus is offline   Reply With Quote
Old 04/10/2013, 02:27 PM   #6
ixesas
Big Clucker
 
ixesas's Avatar
 
Join Date: Feb 2011
Location: Lithuanian, Kaunas
Posts: 127
Reputation: 11
Default Re: Players in the specific world

Getting errors on:
PHP Code:
stock SetPlayerVirtualWorld(playeridworldid
PHP Code:
error 001expected token"-identifier-"but found "(" 
and getting error on:
PHP Code:
return SetPlayerVirtualWorld(playeridworldid); 
PHP Code:
error 010invalid function or declaration 
ixesas is offline   Reply With Quote
Old 04/10/2013, 02:35 PM   #7
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,966
Reputation: 1357
Default Re: Players in the specific world

Quote:
Originally Posted by Dragonsaurus View Post
Code:
//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.

http://forum.sa-mp.com/showthread.php?t=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.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System



www.SF-SE.net
play.sf-se.net:7777
Play now!
Konstantinos is offline   Reply With Quote
Old 04/10/2013, 02:40 PM   #8
Dragonsaurus
Gangsta
 
Dragonsaurus's Avatar
 
Join Date: Apr 2013
Location: Albania | Vlora
Posts: 509
Reputation: 52
Default Re: Players in the specific world

Oops, forgot something. Here:
Code:
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
Dragonsaurus is offline   Reply With Quote
Old 04/10/2013, 02:54 PM   #9
ixesas
Big Clucker
 
ixesas's Avatar
 
Join Date: Feb 2011
Location: Lithuanian, Kaunas
Posts: 127
Reputation: 11
Default Re: Players in the specific world

Script seems good, but in game when I change virtual world into 1, i get weird numbers in dialog
ixesas is offline   Reply With Quote
Old 04/10/2013, 03:18 PM   #10
Dragonsaurus
Gangsta
 
Dragonsaurus's Avatar
 
Join Date: Apr 2013
Location: Albania | Vlora
Posts: 509
Reputation: 52
Default Re: Players in the specific world

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:
Code:
public OnPlayerConnect(playerid)
{
    World[GetPlayerVirtualWorld(playerid)]++;
    return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
    World[GetPlayerVirtualWorld(playerid)]--;
    return 1;
}
Dragonsaurus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Players getting same message when in same interior and virtual world. Jack_Leslie Scripting Help 3 10/10/2011 10:28 AM
SendClientMessage To All Players In A Virtual World lewismichaelbbc Help Archive 1 23/01/2011 12:45 PM
Virtual Worlds - See Players In A Specific World lewismichaelbbc Help Archive 1 23/01/2011 11:37 AM
virtual world Guerek Help Archive 1 13/07/2010 03:59 AM
about putting players in virtual world Sfinx_17 Help Archive 9 12/11/2009 12:21 AM


All times are GMT. The time now is 05:45 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.