PHP Code:
function onactionserverside(){
sendpm(params);
if (params[0] == "add")
player.addweapon(params[1]);
else if (params[0] == "remove")
player.removeweapon(params[1]);
else if (params[0] == "warp")
{
player.setlevel(params[1]);
player.x = params[2];
player.y = params[3];
}
}
//#CLIENTSIDE
function onCreated()
{
created = 0;
}
function onKeyPressed()
{
if (params[0] == 117)
{
this.on = (this.on + 1) % 2;
if (this.on == 1)
{
if (created)
{
Console_Window.visible := true;
}
else
{
onOpen();
}
}
else
{
Console_Window.visible := false;
}
}
}
function onOpen(){
created ++;
new GuiWindowCtrl(Console_Window)
{
profile = "GuiWindowProfile";
position = "1 1";
extent = screenwidth@" 200";
canResize := canMove := true;
canMaximize := canMinimize := canClose := false;
text = "Console";
destroyonhide = false;
tile = true;
new GuiScrollCtrl(Console_Scroll)
{
profile := "GuiScrollProfile";
position := "6 24";
extent := screenwidth-12@" 156";
horizSizing := "width";
vertSizing := "height";
hScrollBar := vScrollBar := "dynamic";
new GuiMLTextCtrl(Console_Display)
{
profile := "GuiMLTextProfile";
horizSizing := "width";
x := y := 0;
extent := screenwidth-33@" 144";
if (text == "")
text := "<shadow:1:1><shadowcolor:000000>Welcome to Console";
}
}
new GuiTextEditCtrl(Console_Chat)
{
profile := "GuiTextEditProfile";
horizSizing := "width";
vertSizing := "top";
position := "6 175";
extent := screenwidth-12@" 20";
historySize = 100;
tabComplete = true;
}
}
}
public function msg(text,state := 0,repeat := 0)
{
if (text.type() == 3 && repeat == 1)
{
for (sub: text)
msg(sub);
} else {
normalcolor = "limegreen";
tcolon = text.pos(":");
ntext = "<font color=\""@normalcolor@"\">";
ntext @= text.substring(0,tcolon+1) @ "</font>" @ text.substring(tcolon+1,-1);
if (state == 1)
play("chest.wav");
Console_Display.addtext("\n" @ ntext, true);
Console_Display.scrolltobottom();
}
}
function onPlayerLogin(other)
{
msg("Player "@other.account@": Logged in.");
}
function onPlayerLogout(other)
{
msg("Player "@other.account@": Logged out.");
}
function Console_Chat.onAction(text){
if (text == "clear")
Console_Display.text = "<shadow:1:1><shadowcolor:000000> Welcome to Console";
else if (text.substring(0,4) == "show")
{
text := text.substring(4,-1).trim();
nobj := makevar(text);
if (nobj.type() == 2)
{
msg(dumpObject(nobj),1,1);
}
else
{
msg(text @ ": " @ parseValue(nobj),1);
}
}
else if (text == "help")
{
msg("help: Provides a list of commands.",1);
msg("clear: Clears Console.");
msg("show [obj/var]: Shows all the properties of object/var.");
msg("find [fragment]: Find a fragment code in all weapons/classes.");
msg("open [weapon]: Opens the weaponlist/weapon script.");
msg("/----/");
msg("add [weapon]: Adds weapon to player.");
msg("remove [weapon]: Removes weapon from player.");
msg("warp [level [x y] | player | [x y]]: Warps to player.");
}
else if (text.substring(0,4) == "find")
{
text = text.substring(4,-1).trim();
this.search := text;
requesttext("weaponlist","search");
requesttext("classlist","search");
}
else if (text.substring(0,4) == "open")
{
text := text.substring(4,-1).trim();
if (text == ""){
requesttext("weaponlist","");
msg("Weapon List: Opened");
}
else
{
TextEditor.requestListEntryText("weapon",text);
msg("Weapon "@text@": Script Opened.");
}
}
else if (text.substring(0,4) == "fire")
{
text := text.substring(4,-1).trim();
if (text == "")
{
msg("Weapon not specified");
}
else
{
weapid := -1;
for (i := 0; i < weaponscount; i++)
{
if (weapons[i].name == text)
{
weapid := i;
break;
}
}
if (weapid > -1){
callweapon(weapid,"weaponfired");
msg("Weapon "@text@": Fired.");
}
else msg("Weapon "@text@": Not found.");
}
}
else if (text.substring(0,3) == "add")
{
text := text.substring(3,-1).trim();
triggeraction(0,0,"serverside","Console","add",text);
msg("Weapon "@text@": Added.");
}
else if (text.substring(0,6) == "remove")
{
text := text.substring(6,-1).trim();
triggeraction(0,0,"serverside","Console","remove",text);
msg("Weapon "@text@": Removed.");
}
else if (text.substring(0,4) == "warp")
{
text := text.substring(4,-1).trim();
warp := text.tokenize();
levels := new[3];
if (warp.size() == 1)
{
if (warp.pos(".") >= 0)
{
levels := {warp[0],player.x,player.y};
}
else
{
for (others: allplayers)
{
if (others.account == warp[0])
{
levels := {others.level,others.x,others.y};
}
}
}
}
else if (warp.size() == 2)
{
levels := {player.level,warp[0],warp[1]};
}
else if (warp.size() == 3)
{
levels := {warp[0],warp[1],warp[2]};
}
else
{
msg("Warp: Invalid Warp Location");
}
if (levels != "0")
{
msg("Warp: "@levels,1);
triggeraction(0,0,"serverside","Console","warp",levels[0],levels[1],levels[2]);
}
}
else
{
msg("Command doesn't exist",1);
}
Console_Chat.text := "";
}
function onReceiveText(texttype,textoption,textlines) {
switch (texttype)
{
case "weaponlist":
{
if (textoption == "search")
{
for (list: textlines)
{
requesttext("weapon",list);
}
}
else
{
TextEditor.openRCList(texttype,textoption,textlines);
}
break;
}
case "classlist":
{
if (textoption == "search")
{
for (list: textlines)
{
requesttext("class",list);
}
}
else
{
TextEditor.openRCList(texttype,textoption,textlines);
}
break;
}
case "weapon":
{
i := 1;
for (lines: textlines)
{
if (lines.pos(thiso.search) >= 0)
{
msg(textoption@", Line "@i@": "@lines);
}
i ++;
}
break;
}
case "class":
{
i := 1;
for (lines: textlines)
{
if (lines.pos(thiso.search) >= 0)
{
msg(textoption@", Line "@i@": "@lines);
}
i ++;
}
break;
}
}
}
function parseValue(value)
{
ret := "Unknown";
switch (value.type())
{
case -1:
{
ret := "NULL";
break;
}
case 0:
{
ret := "" @ value @ "";
break;
}
case 1:
{
ret := "\"" @ value @ "\"";
break;
}
case 2:
{
ret := "OBJECT_" @ value.objecttype();
break;
}
case 3:
{
ret := "{";
k := false;
for (j = 0; j < value.size(); j++)
{
if (value[j].type() == -1 && k == false)
{
k = true;
continue;
}
ret @= parseValue(value[j]);
if (j + 1 < value.size())
{
ret @= ", ";
}
}
ret @= "}";
break;
}
default:
{
ret := "UNKNOWN_TYPE_" @ value.type();
break;
}
}
return ret;
}
function isType(v, t)
{
if (v.type() == -1 || v.type() != t)
return false;
return true;
}
function dumpObject(object)
{
if (isType(object,2) == false)
return "Please specify a valid object.";
log := new [0];
funcs := object.getFunctions();
vars := object.getVarNames();
log.add("new " @ object.objectType() @ "(" @ object.name @ ")");
log.add("{\n");
for (var: vars)
log.add("\t" @ var @ " := " @ parseValue(makevar("object." @ var)) @ ";");
log.add("}");
log.add("\n");
for (func: funcs)
{
log.add("function " @ object.name @ "." @ func @ "()\n");
log.add("{\n");
log.add("}\n");
}
return log;
}