Eeek!
This:
PHP Code:
function onActionServerSide()
{
switch (params[0])
{
case "Profile":
{
this.player.clear();
for (temp.i = 0; temp.i < allplayerscount; temp.i ++)
if (params[1] in | allplayers[temp.i].x,allplayers[temp.i].x + 3 | && params[2] in | allplayers[temp.i].y,allplayers[temp.i].y + 3 | && allplayers[temp.i].level != NULL)
{
this.player = allplayers[temp.i];
triggerClient("weapon",this.name,"Profile",this.player,this.player.clientr.communityname,this.player.clientr.upgradestatus);
break;
}
}
}
}
is all wrong. Not only are you looking through allplayerscount, which is every player on the server and not the level, but you should also use foreach loops.
PHP Code:
function onActionServerSide(cmd) {
switch (cmd) {
case "profile":
for (temp.pl : players) {
if (pl.x in |x, x + 3| && pl.y in |y, y + 3| && pl != player) {
triggerClient("weapon", this.name, "profile", pl.account, pl.communityname, pl.upgradestatus);
}
}
break;
}
}
Your trigger also had a few errors:
- You were sending "this.account" which referred directly to the player object, not the player's account. This works because of some guess work in Gscript which converts it to a string based on the object's name, but the proper way to do it is 'this.player.account'.
- You were using 'player.clientr.communityname', 'player.clientr.upgradestatus' -- I see that you're saying to define those on login, but there's no reason to since they are all values of the TServerPlayer object.
In addition, you should use temporary variables instead of variables on the weapon in order to save memory and make the code cleaner.
PHP Code:
temp.pl = allplayers[temp.i];
// instead of
this.pl = allplayers[temp.i];
However, this still isn't right. There's no reason to go serverside in order to find out where a player you're right clicking is. If anything, you won't be able to right click players because by the time the trigger reaches the server the player may have moved, especially if you lag.
A small snippet with clientside finding players:
PHP Code:
function onActionServerSide(cmd, acc) {
if (cmd == "profile") {
temp.pl = findPlayer(acc);
triggerClient("weapon", this.name, "profile", pl.account, pl.communityname, pl.upgradestatus);
}
}
//#CLIENTSIDE
function onMouseDown(button) {
if (button == "right") {
temp.pl = findPlayerAtPosition(mousex, mousey);
if (pl != null) {
triggerServer("weapon", this.name, "profile", pl.account);
}
}
}
function findPlayerAtPosition(x, y) {
for (temp.pl : findNearestPlayers(x, y)) {
if (pl.x in |x, x + 3| && pl.y in |y, y + 3| && pl != player) {
return pl;
}
}
}
And also, in your onCreated event, this is going to cause an error if Profile_Window has not been defined yet.
PHP Code:
Profile_Window.hide();
should be:
PHP Code:
if (Profile_Window.visible) {
Profile_Window.hide();
}
I don't mean to be rude, but I'd suggest this thread be moved out of the code gallery.