// Simple chat processing example. // If the player sends a command, the server does what the command says. // You can also modify the chat message before it is sent to clients by modifying text_out //#include "MakeSeed.as"; //#include "MakeCrate.as"; //#include "MakeScroll.as"; void onInit(CRules@ this) { this.addCommandID("playsound"); } bool onServerProcessChat(CRules@ this, const string& in text_in, string& out text_out, CPlayer@ player) { if (player is null) return true; CBlob@ blob = player.getBlob(); if (blob is null) { return true; } bool CanDo = CanDoCommands(player.getUsername()); if (sv_test || CanDo) { Vec2f pos = blob.getPosition(); int team = blob.getTeamNum(); // single word commands if (text_in == "!sayhello") { CBitStream params; params.write_string("MigrantSayHello"); this.SendCommand(this.getCommandID("playsound"),params); } else if (text_in == "!scream") { CBitStream params; params.write_string("man_scream"); this.SendCommand(this.getCommandID("playsound"),params); } else if (text_in == "!no") { CBitStream params; params.write_string("MigrantSayNo"); this.SendCommand(this.getCommandID("playsound"),params); } else if (text_in == "!snore") { CBitStream params; params.write_string("MigrantSleep"); this.SendCommand(this.getCommandID("playsound"),params); } else if (text_in == "!groan") { CBitStream params; params.write_string("ZombieGroan1"); this.SendCommand(this.getCommandID("playsound"),params); } else if (text_in == "!sayduh") { CBitStream params; params.write_string("SkeletonSayDuh"); this.SendCommand(this.getCommandID("playsound"),params); } else if (text_in == "!yah") { CBitStream params; params.write_string("WraithDie"); this.SendCommand(this.getCommandID("playsound"),params); } // else if (text_in.substr(0, 1) == "!") { // check if we have tokens string[]@ tokens = text_in.split(" "); if (tokens.length > 1) { // and commands with more than one word under here. if(tokens[0]=="!magicshark") // 1st word is whatever just to name it, use an exclamation mark { CPlayer@ user = GetPlayer(tokens[1]); // 2nd word is the our chosen persons username int newteam = parseInt(tokens[2]); // 3rd word(number) is to set the team number, only works on local still // so the command would be !magicshark an_obamanation 3 if(user !is null) // chosen player exisits? { CBlob@ p = user.getBlob(); CBlob@ b = server_CreateBlob("shark", team, p.getPosition()); if (b !is null) // our new blob exisits? { b.server_SetPlayer(user); // set the chosen player as to the new blob p.server_SetPlayer(null); // kill the old blob straight up incase something goes wrong p.server_Die(); // ^^^^ b.Tag('Invincible'); b.AddScript('EmoteBubble.as'); // causes issues on server if not added to non-player blob b.AddScript('StandardControls.as'); b.AddScript('StandardPickup.as'); b.AddScript('ActivateHeldObject.as'); b.AddScript('ArcherLogic.as'); b.AddScript('FireMagicOrb.as'); b.RemoveScript('Shark.as'); b.RemoveScript('AnimalBrain.as'); b.server_setTeamNum(newteam); // doesnt work CSprite@ sprite = b.getSprite(); if (sprite !is null) { sprite.RemoveScript('Shark.as'); sprite.RemoveScript('HealthBar.as'); sprite.RemoveScript('SeatsGUI.as'); } CMovement@ movement = b.getMovement(); if (movement !is null) { movement.AddScript('FaceAimPosition.as'); movement.AddScript("RunnerMovementInit.as"); movement.AddScript("RunnerMovement.as"); movement.RemoveScript('AquaticAnimal.as'); } CShape@ shape = b.getShape(); if (shape !is null) { shape.SetGravityScale(0.2f); // doesnt work } CBrain@ brain = b.getBrain(); if (brain !is null) { brain.server_SetActive(false); brain.RemoveScript('AnimalBrain.as'); } b.getAttachments().AddAttachmentPoint("PICKUP", true); b.getAttachments().AddAttachmentPoint("SEAT", true); AttachmentPoint@ ap = b.getAttachments().getAttachmentPointByName("SEAT"); ap.offset = Vec2f(0.0f,-12.0f); CBlob@ c = server_CreateBlob('chicken',0,b.getPosition()); c.AddScript('SeatHop.as'); c.Tag('Invincible'); b.server_AttachTo(c, "SEAT"); } } } // !turn username into a bison else if(tokens[0]=="!turn" && tokens[2]=="into" && tokens[3]=="a") { CPlayer@ user = GetPlayer(tokens[1]); // 2nd word get username string blobname = tokens[4]; // 4th word is the new blob name. crate, bison, migrant, etc. if(user !is null && getName(blobname)) // chosen player exists? { CBlob@ playerblob = user.getBlob(); CBlob@ newblob = server_CreateBlob( blobname, team, playerblob.getPosition()); if (newblob !is null) // our new blob exists? { newblob.server_SetPlayer(user); // set the chosen player as to the new blob playerblob.server_SetPlayer(null); playerblob.server_Die(); newblob.AddScript('StandardControls.as'); newblob.AddScript('StandardPickup.as'); newblob.AddScript('ActivateHeldObject.as'); newblob.AddScript('EmoteBubble.as'); newblob.AddScript('DrawHoverMessages.as'); CMovement@ movement = newblob.getMovement(); if (movement !is null) { movement.AddScript('FaceAimPosition.as'); movement.AddScript("RunnerMovementInit.as"); movement.AddScript("RunnerMovement.as"); } } } } //!doaflip username else if(tokens[0]=="!doaflip") { CPlayer@ user = GetPlayer(tokens[1]); if(user !is null) // chosen player exisits? { CBlob@ playerblob = user.getBlob(); if (playerblob !is null) // our new blob exisits? { //Add Rolling script; } } } //else if something else... blah blah blah } // try to spawn an actor with this name !actor if (tokens.length == 1) { string name = text_in.substr(1, text_in.size()); if (server_CreateBlob(name, team, pos) is null) { client_AddToChat("blob " + text_in + " not found", SColor(255, 255, 0, 0)); } } } } return true; } // Add the people you want to be able to do the commands in here bool CanDoCommands(string username) { return username == "Monkey_Feats" || username == "an_obamanation" || username == "3rdperson" || username == "Etc"; } bool getName(string name) { string[] blobnames = { //animals "chicken", "bison", "shark", "fishy", "egg", //characters "knight", "archer", "builder", "necromancer", "greg", "princess", "trader", "dummy", "archer_fem_dummy", "builder_fem_dummy", "knight_fem_dummy", "orb", "migrant", //natural "bush", "flowers", "tree_pine", "tree_bushy", "grain", "grain_plant", "chicken", "mat_seed", //structures/industry "hall", "building", "trampoline", "wooden_door", "stone_door", "ladder", "platform", "trap_block", "mounted_bow", "spikes", "archershop", "buildershop", "knightshop", "boatshop", "vehicleshop", "quarters", "storage", "drill", "factory", "saw", "fireplace", "tunnel", "workbench", "tradingpost", "ctf_flag", "flag base", "tradingpost", "tent", //old buildings "barracks", "bed", "dorm", "kitchen", "nursery", "research", "__storage__old", //vehicles "catapult", "ballista", "raft", "longboat", "warboat", "dinghy", "airship", "bomber", //items "lantern", "boulder", "bucket", "chest", "crate", "log", "powerup", "sponge", "scroll", "heart", "steak", "food", "keg", "bomb", "mine", "satchel", "waterbomb", "warboat", "arrow", "ballista_bolt", //mats "mat_wood", "mat_stone", "mat_gold", "mat_firearrows", "mat_bombarrows", "mat_waterarrows", "mat_bombs", //components... really "bolter", "spiker", "dispenser", "lamp", "obstructor", "receiver", "toggle", "transistor", "diode", "emitter", "inverter", "junction", "magazine", "oscillator", "randomizer", "wire", "tee", "elbow", "coin_slot", "lever", "pressure_plate", "push_button", "sensor" }; for (uint i = 0; i < blobnames.length; i++) { string blobname = blobnames[i]; if (name == blobname) { return true; } } return false; } CPlayer@ GetPlayer(string username) { username= username.toLower(); int playersAmount= getPlayerCount(); for(int i=0;i=3 && player.getUsername().toLower().findFirst(username,0)==0)){ return player; } } return null; } bool onClientProcessChat(CRules@ this, const string& in text_in, string& out text_out, CPlayer@ player) { if (text_in == "!debug" && !getNet().isServer()) { // print all blobs CBlob@[] all; getBlobs(@all); for (u32 i = 0; i < all.length; i++) { CBlob@ blob = all[i]; print("[" + blob.getName() + " " + blob.getNetworkID() + "] "); if (blob.getShape() !is null) { CBlob@[] overlapping; if (blob.getOverlapping(@overlapping)) { for (uint i = 0; i < overlapping.length; i++) { CBlob@ overlap = overlapping[i]; print(" " + overlap.getName() + " " + overlap.isLadder()); } } } } } return false; } void onCommand(CRules@ this,u8 cmd,CBitStream @params) { if(cmd==this.getCommandID("playsound")) { string soundname; if(!params.saferead_string(soundname)) { return; } Sound::Play(soundname + ".ogg"); } }