Please see
this for your GUIs.
Also, I know it's personal preference, but it really would be nice on our (mine, at least) eyes if you would add line breaks every now and then.
Your code is also hard to follow in some places because you do not consistently indent.
PHP Code:
function onCreated() {
if (condition) {
if (! condition2()) {
hi();
}
hi2();
}
}
It's a lot easier to follow if you always indent when using braces.
At the very first few lines, you can do this:
PHP Code:
function onActionServerSide() {
if (clientr.clan == null) {
return;
}
which will end the function, rather then adding a big check which just turns out to be confusing.
Around line 6, you're doing (and also near the 'update' command)
PHP Code:
player.nick = #n@" -"@clientr.position@"- ";
which should be (GS2):
PHP Code:
player.nick = player.nick SPC "-" @ clientr.position @ "-";
or even
PHP Code:
player.nick = format("%s -%s-", player.nick, clientr.position);
You can also name your parameters for easier recognition by yourself/others.
PHP Code:
function onActionServerSide(cmd) {
if (cmd == "test") { // as opposed to params[0] == "test"
// code
}
}
Instead of doing
PHP Code:
pl.clientr.clan.add(clientr.clan);
pl.clientr.position.add("Recruit");
you should use multi-dimensional arrays to avoid some kind of synchronization error.
PHP Code:
clientr.clans.add({clan_name, position}); // note that you'd have to update all your other code to reflect this
You should remove the sleeps, they serve absolutely no purpose that I can see besides potentially messing up the script (sleeps tend to break things).
For promoting/demoting, it would be a lot simpler to do something like
PHP Code:
temp.ranks = {"Recruit", "Warrior", "Gladiator", "Legendary Gladiator", "Champion", "Ancient Warrior"};
temp.plRank = ranks.index(@ pl.clientr.position);
if (plRank > - 1) {
if (plRank == ranks.size() - 1) {
// ancient warrior
player.chat = "You cannot promote Ancient Warriors!";
} else {
pl.clientr.position = ranks[plRank + 1];
pl.chat = "Rank changed to" SPC pl.clientr.position SPC "by" SPC player.account @ "!";
player.chat = "Changed" SPC pl.account @ "'s position to" SPC pl.clientr.position @ "!";
}
} else {
player.chat = "You cannot promote leaders!";
}
Demote would be something like
PHP Code:
temp.ranks = {"Recruit", "Warrior", "Gladiator", "Legendary Gladiator", "Champion", "Ancient Warrior"};
temp.plRank = ranks.index(@ pl.clientr.position);
if (plRank > - 1) {
if (plRank == 0) {
player.chat = "You cannot demote this player any further!";
} else {
pl.clientr.position = ranks[plRank - 1];
pl.chat = "Rank changed to" SPC pl.clientr.position SPC "by" SPC player.account @ "!";
player.chat = "Changed" SPC pl.account @ "'s position to" SPC pl.clientr.position @ "!";
}
} else {
player.chat = "You cannot demote leaders!";
}
Also, make sure you don't do this
PHP Code:
player.chat = "Changed" SPC pl @ "'s rank";
because 'pl' is a player object. In GS2, when you attempt to print an object, it outputs 'object.name', which happens to be the players account name. Instead you should do something like
PHP Code:
pl.chat = "Changed " @ pl.account @ "'s rank";