Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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";
- int minTimeBetweenInSeconds = 1;
- bool onServerProcessChat( CRules@ this, const string& in text_in, string& out text_out, CPlayer@ player )
- {
- if (player is null)
- return true;
- const bool canSpawn = sv_test || player.isMod();
- if (text_in == "!bot" && player.isMod()) // TODO: whoaaa check seclevs
- {
- CPlayer@ bot = AddBot( "Henry" );
- return true;
- }
- //spawning things
- CBlob@ blob = player.getBlob();
- if (blob is null) {
- return true;
- }
- // Check the time since their last message, and see if they should be allowed to send another
- if (blob.exists("message sent"))
- {
- s32 timeDifference = getGameTime() - blob.get_s32("message sent");
- if(timeDifference < (50 * minTimeBetweenInSeconds))
- {
- client_AddToChat( "Please stop spamming", SColor(255, 255, 0,0));
- return false;
- }
- blob.set_s32("message sent", getGameTime());
- }
- else
- {
- blob.set_s32("message sent", getGameTime());
- }
- if (text_in == "!tree" && canSpawn)
- {
- server_MakeSeed( blob.getPosition(), "tree_pine", 600, 1, 16 );
- }
- else if (text_in == "!btree" && canSpawn)
- {
- server_MakeSeed( blob.getPosition(), "tree_bushy", 400, 2, 16 );
- }
- else if (text_in == "!flowers" && canSpawn)
- {
- server_CreateBlob( "Entities/Natural/Flowers/Flowers.cfg", blob.getTeamNum(), blob.getPosition() );
- }
- else if (text_in == "!catapult" && canSpawn)
- {
- server_CreateBlob( "Entities/Vehicles/Catapult/Catapult.cfg", blob.getTeamNum(), blob.getPosition() );
- }
- else if (text_in == "!stones" && canSpawn)
- {
- CBlob@ b = server_CreateBlob( "Entities/Materials/MaterialStone.cfg", blob.getTeamNum(), blob.getPosition() );
- if (b !is null) {
- b.server_SetQuantity(320);
- }
- }
- else if (text_in == "!arrows" && canSpawn)
- {
- for (int i = 0; i < 3; i++)
- {
- CBlob@ b = server_CreateBlob( "Entities/Materials/MaterialArrows.cfg", blob.getTeamNum(), blob.getPosition() );
- if (b !is null) {
- b.server_SetQuantity(30);
- }
- }
- }
- else if (text_in == "!bombs" && canSpawn)
- {
- // for (int i = 0; i < 3; i++)
- CBlob@ b = server_CreateBlob( "Entities/Materials/MaterialBombs.cfg", blob.getTeamNum(), blob.getPosition() );
- if (b !is null) {
- b.server_SetQuantity(30);
- }
- }
- else if (text_in == "!spawnwater" && canSpawn)
- {
- getMap().server_setFloodWaterWorldspace(blob.getPosition(),true);
- }
- else if (text_in == "!seed")
- {
- // crash prevention
- }
- else if (text_in == "!killme")
- {
- blob.server_Hit( blob, blob.getPosition(), Vec2f(0,0), 4.0f, 0);
- }
- else if (text_in == "!crate" && canSpawn)
- {
- client_AddToChat( "usage: !crate BLOBNAME [DESCRIPTION]", SColor(255, 255, 0,0));
- server_MakeCrate( "", "", 0, blob.getTeamNum(), Vec2f( blob.getPosition().x, blob.getPosition().y - 30.0f ) );
- }
- else if (text_in == "!debug" && player.isMod())
- {
- // print all blobs
- CBlob@[] all;
- getBlobs( @all );
- for (u32 i=0; i < all.length; i++)
- {
- CBlob@ blob = all[i];
- print("["+blob.getName()+" " + blob.getNetworkID() + "] ");
- }
- }
- else if (text_in.substr(0,1) == "!")
- {
- // check if we have tokens
- string[]@ tokens = text_in.split(" ");
- if (tokens.length > 1)
- {
- if (tokens[0] == "!crate" && canSpawn)
- {
- int frame = tokens[1] == "catapult" ? 1 : 0;
- string description = tokens.length > 2 ? tokens[2] : tokens[1];
- server_MakeCrate( tokens[1], description, frame, -1, Vec2f( blob.getPosition().x, blob.getPosition().y ) );
- }
- else if (tokens[0] == "!team" && canSpawn)
- {
- int team = parseInt(tokens[1]);
- blob.server_setTeamNum(team);
- }
- else if (tokens[0] == "!scroll" && canSpawn)
- {
- server_MakePredefinedScroll( blob.getPosition(), tokens[1] );
- }
- else if (tokens[0] == "!spawn" && canSpawn) // Allow players to spawn a specified amount of blobs
- {
- int amount = tokens.length > 2 ? parseInt(tokens[2]) : 1;
- int count = 0;
- for (count = 0; count < amount; count++)
- {
- server_CreateBlob( tokens[1], -1, blob.getPosition() );
- }
- }
- return true;
- }
- // try to spawn an actor with this name !actor
- string name = text_in.substr(1, text_in.size());
- if (canSpawn && server_CreateBlob( name, -1, blob.getPosition() ) is null) {
- client_AddToChat( "blob " + text_in + " not found", SColor(255, 255, 0,0));
- }
- }
- return true;
- }
- 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 true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement