Advertisement
Klee_from_Space

Untitled

Dec 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 45.14 KB | None | 0 0
  1. // ============================================================
  2. // Project Information
  3. // ============================================================
  4. // Project          :   Roleplay Server
  5. // Author           :   Zapk
  6. // Description      :   A new lightweight roleplaying framework.
  7. // ============================================================
  8. // I highly recommend using Script_Player_Persistence with this.
  9. // Do not modify anything in this file!
  10. // ============================================================
  11.  
  12. // Set variables.
  13. $oocmute = 0;
  14. $RoleplayServer::Version = "0.3.0";
  15.  
  16. // Dev function to reload the scripts.
  17. function RS_Reload()
  18. {
  19.     exec("./server.cs");
  20. }
  21.  
  22. // Load libraries.
  23. exec("./lib/color.cs");
  24. //exec("./lib/decals.cs");
  25.  
  26. // Load preferences file.
  27. if(isFile("Add-Ons/System_ReturnToBlockland/server.cs") && !$RTB::Hooks::ServerControl)
  28. {
  29.     exec("Add-Ons/System_ReturnToBlockland/hooks/serverControl.cs");
  30. }
  31.  
  32. RTB_registerPref("Disable Player Names", "Roleplay - Basic", "$RoleplayServer::DisablePlayerNames", "bool", "Server_Roleplay", 1, 0, 0);
  33. RTB_registerPref("Disable Typing Names", "Roleplay - Basic", "$RoleplayServer::DisableTypingNames", "bool", "Server_Roleplay", 1, 0, 0);
  34.  
  35. RTB_registerPref("Local OOC", "Roleplay - Radiuses", "$RoleplayServer::RadiusLOOC", "int 1 64", "Server_Roleplay", 16, 0, 0);
  36. RTB_registerPref("Talking", "Roleplay - Radiuses", "$RoleplayServer::RadiusTalking", "int 1 64", "Server_Roleplay", 16, 0, 0);
  37. RTB_registerPref("/recognize", "Roleplay - Radiuses", "$RoleplayServer::RadiusRecognize", "int 1 64", "Server_Roleplay", 16, 0, 0);
  38. RTB_registerPref("/w", "Roleplay - Radiuses", "$RoleplayServer::RadiusWhispering", "int 1 64", "Server_Roleplay", 4, 0, 0);
  39. RTB_registerPref("/y", "Roleplay - Radiuses", "$RoleplayServer::RadiusYelling", "int 1 64", "Server_Roleplay", 32, 0, 0);
  40.  
  41. RTB_registerPref("Talking", "Roleplay - Timeouts", "$RoleplayServer::TimeoutTalking", "int 100 60000", "Server_Roleplay", 1000, 0, 0);
  42. RTB_registerPref("OOC", "Roleplay - Timeouts", "$RoleplayServer::TimeoutOOC", "int 100 60000", "Server_Roleplay", 10000, 0, 0);
  43. RTB_registerPref("Local OOC", "Roleplay - Timeouts", "$RoleplayServer::TimeoutLOOC", "int 100 60000", "Server_Roleplay", 1000, 0, 0);
  44. RTB_registerPref("Reporting", "Roleplay - Timeouts", "$RoleplayServer::TimeoutAdminChat", "int 100 60000", "Server_Roleplay", 5000, 0, 0);
  45. RTB_registerPref("/roll", "Roleplay - Timeouts", "$RoleplayServer::TimeoutRoll", "int 100 60000", "Server_Roleplay", 2000, 0, 0);
  46. RTB_registerPref("/setName", "Roleplay - Timeouts", "$RoleplayServer::TimeoutSetName", "int 100 60000", "Server_Roleplay", 10000, 0, 0);
  47. RTB_registerPref("/setFreq", "Roleplay - Timeouts", "$RoleplayServer::TimeoutSetFreq", "int 100 60000", "Server_Roleplay", 5000, 0, 0);
  48. RTB_registerPref("/recognize", "Roleplay - Timeouts", "$RoleplayServer::TimeoutRecognize", "int 100 60000", "Server_Roleplay", 5000, 0, 0);
  49.  
  50. // Load other branches.
  51. exec("./src/datablocks.cs");
  52.  
  53. // Makes particle datablocks for each icon so clients download them.
  54. function RS_LoadIcons()
  55. {
  56.     %pattern = "Add-Ons/Server_Roleplay/res/icons/*.png";
  57.  
  58.     %file = findFirstFile(%pattern);
  59.  
  60.     while(isFile(%file))
  61.     {
  62.         %dbName = "RS_Icon_" @ getSafeVariableName(fileBase( %file ));
  63.  
  64.         if(!isObject(nameToID( %dbName )))
  65.         {
  66.             datablock ParticleData(_RS_TempIcon)
  67.             {
  68.                 textureName = strreplace(%file, ".png", "");
  69.             };
  70.  
  71.             _RS_TempIcon.setName( %dbName );
  72.  
  73.             echo("Roleplay Server: Added datablock '" @ %dbName @ "' for icon '" @ fileName(%file) @ "'.");
  74.         }
  75.  
  76.         %file = findNextFile(%pattern);
  77.     }
  78. }
  79.  
  80. schedule(0, 0, "RS_LoadIcons");
  81.  
  82. function gameConnection::getUserIcon(%this)
  83. {
  84.     %icon = "user";
  85.  
  86.     if(%this.isAdmin)
  87.     {
  88.         %icon = "star";
  89.  
  90.         if(%this.isSuperAdmin)
  91.         {
  92.             %icon = "shield";
  93.         }
  94.     }
  95.  
  96.     return %icon;
  97. }
  98.  
  99. package RS_Package
  100. {
  101.     function serverCmdStartTalking(%this)
  102.     {
  103.         if($RoleplayServer::DisableTypingNames)
  104.         {
  105.             return;
  106.         }
  107.  
  108.         Parent::serverCmdStartTalking(%this);
  109.     }
  110.     function gameConnection::onClientEnterGame(%this) //set the warned variable so it can be used later
  111.     {
  112.         if($warned[%this] < 1)
  113.         {
  114.             $warned[%this] = 0;
  115.         }
  116.     }
  117.     function serverCmdwarn(%this, %target, %msg) //warn a player of their wrongdoing
  118.     {
  119.         if (!%this.isAdmin)
  120.         {
  121.             messageClient(%target, '', "\c3[You have been warned by \c6" @ %this.name @ "\c3 for ''\c6" @ %msg @ "\c3''\c3]");
  122.             $warned[%target] += 1;
  123.         }
  124.     }
  125.     function serverCmdtimeswarned(%this, %target) //see how many times a player has been warned
  126.     {
  127.         if (!%this.isAdmin)
  128.         {
  129.             messageClient("\c3" @ %target @ "\c6 has been warned \c3" @ $warned[%target] @ "\c6 times.");
  130.         }
  131.     }
  132.     function serverCmdclearwarns(%this, %target) //clear how many times a player has been warned
  133.     {
  134.         if (!%this.isAdmin)
  135.         {
  136.             $warned[%target] = 0;
  137.         }
  138.     }
  139.     function serverCmdtoggleOOC(%this) //turn the OOC off
  140.     {
  141.         if (!%this.isAdmin)
  142.         {
  143.             if ($oocmute == 0)
  144.             {
  145.                 $oocmute = 1;
  146.                 announce("\c6The \c3OOC \c6has been disabled!");
  147.             }
  148.             else if($oocmute == 1)
  149.             {
  150.                 $oocmute = 0;
  151.                 announce("\c6The \c3OOC \c6has been enabled!");
  152.             }
  153.         }
  154.     }
  155.     function serverCmdMute(%this, %target) //mute a player from using the OOC
  156.     {
  157.         if (!%this.isAdmin)
  158.         {
  159.             $mute[%target] = 1;
  160.             messageClient(%target, '', "\c6You have been OOC muted by \c3" @ %this.name);
  161.             echo(%this.name SPC "muted" SPC %target.name);
  162.             messageClient(%this, '', "\c6You muted \c3" @ %target.name);
  163.         }
  164.     }
  165.     function serverCmdTeamMessageSent(%this, %msg) //use the OOC (shortcut)
  166.     {
  167.         if ($oocmute == 1)
  168.         {
  169.             messageClient("\c3The OOC is disabled!");
  170.         }
  171.         else
  172.         {
  173.             if ($mute[%this] = 1)
  174.             {
  175.                 messageClient("\c3You are muted!");
  176.             }
  177.             else
  178.             {
  179.                 serverCmdOOC(%this, %msg);
  180.             }
  181.         }
  182.     }
  183.  
  184.     function serverCmdMessageSent(%this, %msg)
  185.     {
  186.         if(!%this.hasSpawnedOnce || !isObject(%this.player))
  187.         {
  188.             //If they haven't spawned, OOC.
  189.             if ($oocmute == 1) //Check if the OOC is on or off
  190.             {
  191.                 messageClient("\c3The OOC is disabled!");
  192.             }
  193.             else
  194.             {
  195.                 if ($mute[%this] = true)
  196.                 {
  197.                     messageClient("\c3You are muted!");
  198.                 }
  199.                 else
  200.                 {
  201.                     serverCmdOOC(%this, %msg);
  202.                 }
  203.             }
  204.             return;
  205.         }
  206.         else if(%this.roleplayName $= "")
  207.         {
  208.             //Warn people who have no character name.
  209.             messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have a character name. Type /rpHelp.');
  210.             return;
  211.         }
  212.  
  213.         if(%msg $= "")
  214.         {
  215.             //Get rid of empty messages.
  216.             return;
  217.         }
  218.  
  219.         %firstLetter = getSubStr(%msg, 0, 1);
  220.         %rest = getSubStr(%msg, 1, strlen(%msg));
  221.  
  222.         if(%firstLetter $= ",")
  223.         {
  224.             serverCmdLOOC(%this, %rest);
  225.             return;
  226.         }
  227.  
  228.         if(%firstLetter $= "^")
  229.         {
  230.             serverCmdAdminChat(%this, %rest);
  231.             return;
  232.         }
  233.  
  234.         if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["messageSent"] <= $RoleplayServer::Timeout["Talking"])
  235.         {
  236.             %secondsLeft = mCeil(($RoleplayServer::Timeout["Talking"] - (getSimTime() - %this.lastCommandUse["messageSent"])) / 1000);
  237.             messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to talk again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  238.             return;
  239.         }
  240.    
  241.         %this.lastCommandUse["messageSent"] = getSimTime();
  242.  
  243.         %msg = StripMLControlChars(%msg);
  244.  
  245.         %pos = %this.player.getPosition();
  246.         %image = %this.player.getMountedImage(0);
  247.  
  248.         //If they're talking through a handheld radio.
  249.         if(isObject(%image) && %image.getName() $= "RadioImage" && %this.radioFrequency !$= "")
  250.         {
  251.             for(%i = 0; %i < ClientGroup.getCount(); %i++)
  252.             {
  253.                 %client = ClientGroup.getObject(%i);
  254.        
  255.                 if(!isObject(%client.player))
  256.                     continue;
  257.  
  258.                 if(%client.player.hasRadio() && %client.radioFrequency $= %this.radioFrequency)
  259.                 {
  260.                     //If they have a radio and are on the same frequency.
  261.                     messageClient(%client, '', '<color:6F9922>%1 (Radio): "%2"', %client.getOtherCharacterName(%this), %msg);
  262.                     %client.play2D(RoleplayChatSound);
  263.                 }
  264.                 else if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["Talking"])
  265.                 {
  266.                     //Or if they're close enough to hear the voice.
  267.                     messageClient(%client, '', '<color:F8D690>%1 (Radio):, "%2"', %client.getOtherCharacterName(%this), %msg);
  268.                     %client.play2D(RoleplayChatSound);
  269.                 }
  270.             }
  271.  
  272.             %this.player.playThread(3,"talk");
  273.             %this.player.schedule(strlen(%msg) * 50, playThread, 3, "root");
  274.  
  275.             RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") radioed '" @ %msg @ "'", "\c1");
  276.             return;
  277.         }
  278.  
  279.         for(%i = 0; %i < ClientGroup.getCount(); %i++)
  280.         {
  281.             %client = ClientGroup.getObject(%i);
  282.    
  283.             if(!isObject(%client.player))
  284.                 continue;
  285.    
  286.             if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["Talking"])
  287.             {
  288.                 messageClient(%client, '', '<color:F8D690>%1: "%2"', %client.getOtherCharacterName(%this), %msg);
  289.                 %client.play2D(RoleplayChatSound);
  290.             }
  291.         }
  292.  
  293.         %this.player.playThread(3,"talk");
  294.         %this.player.schedule(strlen(%msg) * 50, playThread, 3, "root");
  295.  
  296.         RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") said '" @ %msg @ "'", "\c1", true);
  297.     }
  298.  
  299.     function WeaponImage::onMount(%this, %obj, %slot)
  300.     {
  301.         if(!%this.armReady)
  302.         {
  303.             // If their hand was already up, put it down.
  304.             %obj.playThread(1, "root");
  305.         }
  306.  
  307.         %client = %obj.client;
  308.         %item = %this.item;
  309.  
  310.         if(isObject(%client) && %item.roleplayDescription !$= "")
  311.         {
  312.             if(%item.uiName $= "Radio")
  313.             {
  314.                 %hasFreq = %client.radioFrequency !$= "";
  315.  
  316.                 if(!%hasFreq)
  317.                 {
  318.                     messageClient(%client, '', "\c6You don't have a frequency set. Use \c6/setFreq [frequency]\c6. Your radio won't work until you do so.");
  319.                 }
  320.             }
  321.  
  322.             %client.centerPrint("<font:Palatino Linotype:30><color:A5505E>\xab " @ %item.uiName @ (%hasFreq ? " - " @ %client.radioFrequency @ "MHz \xbb" : " \xbb") @ "<br><color:48333E>" @ %item.roleplayDescription, 4);
  323.         }
  324.  
  325.         return Parent::onMount(%this, %obj, %slot);
  326.     }
  327.  
  328.     function GameConnection::onClientEnterGame(%this)
  329.     {
  330.         Parent::onClientEnterGame(%this);
  331.  
  332.         messageClient(%this, '', '\c6You are now talking in-character by default, %1.', %this.getPlayerName());
  333.  
  334.         if(%this.isAdmin && !%this.hasRPA)
  335.         {
  336.             messageClient(%this, '', '\c6Uh-oh, you\'re missing <color:A6130C>Client_RoleplayAdmin \c6and will not be able to see logs in your console. Ask the host for the link.');
  337.         }
  338.  
  339.         %this.loadRoleplayData();
  340.     }
  341.  
  342.     function GameConnection::onClientLeaveGame(%this)
  343.     {
  344.         RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") left the game.");
  345.  
  346.         if(isObject(%this.f8Zone))
  347.         {
  348.             %this.f8Zone.delete();
  349.         }
  350.  
  351.         Parent::onClientLeaveGame(%this);
  352.     }
  353.  
  354.     function GameConnection::autoAdminCheck(%this)
  355.     {
  356.         %parent = Parent::autoAdminCheck(%this);
  357.  
  358.         RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") joined the game.");
  359.         messageClient(%this, '', '\c7Hey %1, this is a roleplay server. Type <color:A6130C>/rpHelp\c7 for info.', %this.getPlayerName());
  360.         messageClient(%this, '', '\c6Texture \c7& \c6Sound \c7downloads are required to see some roleplay content properly.');
  361.  
  362.         // Admin client handshake.
  363.         commandToClient(%this, 'RPA_Handshake');
  364.  
  365.         return %parent;
  366.     }
  367.  
  368.     function fxDTSBrick::onActivate(%this, %player, %client, %position, %vector)
  369.     {
  370.         Parent::onActivate(%this, %player, %client, %position, %vector);
  371.     }
  372.  
  373.     function doQuitGame()
  374.     {
  375.         if(isObject(ServerGroup))
  376.         {
  377.             saveAllRoleplayData();
  378.         }
  379.  
  380.         Parent::doQuitGame();
  381.     }
  382.  
  383.     function gameConnection::spawnPlayer(%this)
  384.     {
  385.         %parent = Parent::spawnPlayer(%this);
  386.  
  387.         if($RoleplayServer::DisablePlayerNames)
  388.         {
  389.             %this.player.schedule(0, "setShapeNameDistance", 0);
  390.         }
  391.  
  392.         %this.player.tooltipLoop();
  393.  
  394.         return %parent;
  395.     }
  396.  
  397.     function ItemData::onPickup(%this, %obj, %user, %amount)
  398.     {
  399.         Parent::onPickup(%this, %obj, %user, %amount);
  400.         serverCmdReport("c3\ " @ %user @ "\c6picked up an \c3" @ %obj @ "\c6 !");
  401.     }
  402.  
  403.     function Weapon::onPickup(%this, %obj, %player, %amount)
  404.     {
  405.         Parent::onPickup(%this, %obj, %player, %amount);
  406.         serverCmdReport("c3\ " @ %user @ "\c6picked up an \c3" @ %obj @ "\c6 !");
  407.     }
  408.  
  409.     function Item::schedulePop(%this)
  410.     {
  411.         Parent::schedulePop(%this);
  412.     }
  413. };
  414.  
  415. activatePackage(RS_Package);
  416.  
  417. function GameConnection::loadRoleplayData(%this)
  418. {
  419.     %name = "config/server/roleplay/data/" @ %this.getBLID() @ ".txt";
  420.  
  421.     %file = new FileObject();
  422.     %file.openForRead(%name);
  423.  
  424.     if(!%file)
  425.     {
  426.         error("ERROR: GameConnection::loadRoleplayData(" @ %this @ " (BLID: " @ %this.getBLID() @ ")) - failed to open file '" @ %name @ "' for read");
  427.  
  428.         %file.delete();
  429.         return;
  430.     }
  431.  
  432.     echo("Loading roleplay data for BLID " @ %this.getBLID());
  433.  
  434.     while(!%file.isEOF())
  435.     {
  436.         %line = %file.readLine();
  437.  
  438.         %var = getField(%line, 0);
  439.         %val = getFields(%line, 1, 999);
  440.  
  441.         if(strpos(%var, "//") == 0 || %val $= "")
  442.         {
  443.             continue;
  444.         }
  445.  
  446.         switch$(%var)
  447.         {
  448.             case "name":
  449.                 %this.roleplayName = %val;
  450.  
  451.             case "freq":
  452.                 %this.radioFrequency = %val;
  453.  
  454.             case "recog":
  455.                 %rID = getField(%val, 0);
  456.                 %rName = getField(%val, 1);
  457.                 %this.recognizes[%rID, %rName] = true;
  458.         }
  459.     }
  460.  
  461.     %file.close();
  462.     %file.delete();
  463.  
  464.     %this.roleplaySaveLoop(true);
  465. }
  466.  
  467. function gameConnection::saveRoleplayData(%this)
  468. {
  469.     %name = "config/server/roleplay/data/" @ %this.getBLID() @ ".txt";
  470.  
  471.     %file = new FileObject();
  472.     %file.openForWrite(%name);
  473.  
  474.     if(!%file)
  475.     {
  476.         error("ERROR: GameConnection::saveRoleplayData(" @ %this @ " (BLID: " @ %this.getBLID() @ ")) - failed to open file '" @ %name @ "' for write");
  477.  
  478.         %file.delete();
  479.         return;
  480.     }
  481.  
  482.     echo("Saving roleplay data for BLID " @ %this.getBLID());
  483.  
  484.     %file.writeLine("//Roleplay data for " @ %this.getPlayerName() @ ", generated at " @ getDateTime());
  485.  
  486.     if(%this.roleplayName !$= "")
  487.         %file.writeLine("name" TAB %this.roleplayName);
  488.  
  489.     if(%this.radioFrequency !$= "")
  490.         %file.writeLine("freq" TAB %this.radioFrequency);
  491.  
  492.     %i = 0;
  493.     while(true)
  494.     {
  495.         %tag = %this.getTaggedField(%i);
  496.  
  497.         if(%tag $= "")
  498.         {
  499.             break;
  500.         }
  501.  
  502.         %var = getField(%tag, 0);
  503.         %val = getFields(%tag, 1, 999);
  504.  
  505.         if(strpos(%var, "recognizes") == 0)
  506.         {
  507.             %realVar = getSubStr(%var, 10, strlen(%var) - 10);
  508.             %splitPos = strpos(%realVar, "_");
  509.  
  510.             %bl_id = getSubStr(%realVar, 0, %splitPos);
  511.             %theirName = getSubStr(%realVar, %splitPos + 1, strlen(%var) - %splitPos);
  512.  
  513.             %file.writeLine("recog" TAB %bl_id TAB %theirName);
  514.         }
  515.  
  516.         %i++;
  517.     }
  518.  
  519.     %file.close();
  520.     %file.delete();
  521. }
  522.  
  523. function gameConnection::roleplaySaveLoop(%this, %firstTime)
  524. {
  525.     cancel(%this.roleplaySaveLoop);
  526.  
  527.     if(!%firstTime && !isEventPending($LoadSaveFile_Tick_Schedule))
  528.     {
  529.         %this.saveRoleplayData();
  530.     }
  531.  
  532.     %this.roleplaySaveLoop = %this.schedule(5 * 60000, "roleplaySaveLoop");
  533. }
  534.  
  535. function saveAllRoleplayData()
  536. {
  537.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  538.     {
  539.         ClientGroup.getObject(%i).saveRoleplayData();
  540.     }
  541. }
  542.  
  543. function RS_Log(%line, %color, %superAdmin)
  544. {
  545.     if(%line $= "")
  546.     {
  547.         return;
  548.     }
  549.  
  550.     %dateTime = getDateTime();
  551.     %date = strreplace(firstWord(%dateTime), "/", "-");
  552.  
  553.     %fileName = "config/server/roleplay/logs/" @ %date @ ".txt";
  554.  
  555.     %file = new FileObject();
  556.     %file.openForAppend(%fileName);
  557.  
  558.     %file.writeLine("[" @ %dateTime @ "] " @ %line);
  559.  
  560.     %file.close();
  561.     %file.delete();
  562.  
  563.     echo("[Logged]" SPC %line);
  564.  
  565.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  566.     {
  567.         %client = ClientGroup.getObject(%i);
  568.  
  569.         if(%client.isAdmin && (!%superAdmin || %client.isSuperAdmin))
  570.         {
  571.             commandToClient(%client, 'RP_Log', %color @ %line, %superAdmin);
  572.         }
  573.     }
  574. }
  575.  
  576. function Player::tooltipLoop(%this)
  577. {
  578.     cancel(%this.tooltipLoop);
  579.  
  580.     if(!isObject(%this.client))
  581.     {
  582.         return;
  583.     }
  584.  
  585.     %eye = %this.getEyePoint();
  586.     %vec = %this.getEyeVector();
  587.  
  588.     %ray = containerRaycast(%eye, VectorAdd( %eye, VectorScale( %vec, $RoleplayServer::Radius["Yelling"] ) ), $Typemasks::PlayerObjectType, %this);
  589.  
  590.     if(isObject( %obj = firstWord(%ray) ))
  591.     {
  592.         %objC = %obj.client;
  593.  
  594.         if(isObject(%objC))
  595.         {
  596.             if(%this.client.recognizes[%objC.getBLID(), %objC.roleplayName])
  597.             {
  598.                 commandToClient(%this.client, 'centerPrint', "<br><br><br><br>\c6" @ %this.client.getOtherCharacterName(%objC), 0.2);
  599.             }
  600.             else
  601.             {
  602.                 %hue = (mSin($Sim::Time) + 1) * 0.5;
  603.                 %hex = rgbToHex( HSVtoRGB(%hue, 0.5, 1) );
  604.  
  605.                 commandToClient(%this.client, 'centerPrint', "<br><br><br><br><color:" @ %hex @ ">You do not recognize this person.", 0.2);
  606.             }
  607.         }
  608.         else
  609.         {
  610.             commandToClient(%this.client, 'clearCenterPrint');
  611.         }
  612.     }
  613.  
  614.     %this.tooltipLoop = %this.schedule(64, "tooltipLoop");
  615. }
  616.  
  617. function Player::hasRadio(%this)
  618. {
  619.     %max = %this.getDatablock().maxTools;
  620.  
  621.     for(%i = 0; %i < %max; %i++)
  622.     {
  623.         if(%this.tool[%i].uiName $= "Radio")
  624.         {
  625.             return true;
  626.         }
  627.     }
  628.  
  629.     return false;
  630. }
  631.  
  632. function serverCmdRPHelp(%this)
  633. {
  634.     messageClient(%this, '', '\c6This server is running <color:A6130C>Roleplay Server \c6version %1 by Zapkraft.', $RoleplayServer::Version);
  635.     messageClient(%this, '', '\c6\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97');
  636.  
  637.     messageClient(%this, '', '\c6Talking normally produces an in-character message, unless you\'re loading.');
  638.     messageClient(%this, '', '\c6To talk out-of-character globally, use team chat.');
  639.     messageClient(%this, '', '\c6To talk out-of-character to those around you, place a comma (<color:A6130C>,\c6) before your message.');
  640.     messageClient(%this, '', '\c6To perform an action, type <color:A6130C>/me\c6 before your message.');
  641.     messageClient(%this, '', '\c6To describe a local event, type <color:A6130C>/it\c6 before your message.');
  642.     messageClient(%this, '', '\c6To yell, type <color:A6130C>/y\c6 before your message.');
  643.     messageClient(%this, '', '\c6To whisper, type <color:A6130C>/w\c6 before your message.');
  644.     messageClient(%this, '', '\c6To set your character\'s name, type <color:A6130C>/setName [full name]\c6.');
  645.     messageClient(%this, '', '\c6For help with radios, type <color:A6130C>/radioHelp\c6.');
  646.     messageClient(%this, '', '\c6To make people in a radius recognize your name, type <color:A6130C>/recognize\c6.');
  647.     messageClient(%this, '', '\c6To roll a random number, type <color:A6130C>/roll [max]\c6.');
  648.     messageClient(%this, '', '\c6To report a rule-breaker to the admins (or talk to other admins if you are one), place an at-sign (<color:A6130C>@\c6) before your message.');
  649.  
  650.     if(%this.isAdmin)
  651.     {
  652.         messageClient(%this, '', '\c6You are an admin. To see the admin-only commands, type \c0/adminHelp\c6.');
  653.     }
  654.  
  655.     messageClient(%this, '', '\c6\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97');
  656.     messageClient(%this, '', '\c6Use the <color:A6130C>PageUp \c6and <color:A6130C>PageDown \c6keys to scroll (by default).');
  657. }
  658.  
  659. function serverCmdRPCInfo(%this)
  660. {
  661.     serverCmdRPHelp(%this);
  662. }
  663.  
  664. function serverCmdRadioHelp(%this)
  665. {
  666.     messageClient(%this, '', '\c6Radios are useful for communicating from a distance.');
  667.     messageClient(%this, '', '\c6\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97');
  668.  
  669.     messageClient(%this, '', '\c6Talking with a Radio item out will radio in to your current frequency.');
  670.     messageClient(%this, '', '\c6To change your frequency, type <color:A6130C>/setFreq [frequency]\c6.');
  671.     messageClient(%this, '', '\c6Those around will be able to hear you talk into your radio.');
  672.     messageClient(%this, '', '\c6Radio messages show up green if heard through a speaker, and yellow if by voice.');
  673.  
  674.     messageClient(%this, '', '\c6\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97');
  675.     messageClient(%this, '', '\c6Use the <color:A6130C>PageUp \c6and <color:A6130C>PageDown \c6keys to scroll (by default).');
  676. }
  677.  
  678. function serverCmdAdminHelp(%this)
  679. {
  680.     if(!%this.isAdmin)
  681.     {
  682.         messageClient(%this, '', '\c6You aren\'t an admin. You don\'t need to see the admin help.');
  683.         return;
  684.     }
  685.  
  686.     messageClient(%this, '', '\c6Admin commands;');
  687.     messageClient(%this, '', '\c6\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97');
  688.  
  689.     if(isFunction("clearFootsteps"))
  690.     {
  691.         // If they have Server_Stride, help them with that too.
  692.         messageClient(%this, '', '<color:A6130C>/clearFootsteps \c6- Clears all custom footstep & footprint settings.');
  693.         messageClient(%this, '', '<color:A6130C>/setFootstep [string material] [bool hasFootprints]\c6- Assigns the material to your current paint colour.');
  694.     }
  695.  
  696.     messageClient(%this, '', '<color:A6130C>/who \c6- Displays all the players within yelling distance of you.');
  697.     messageClient(%this, '', '<color:A6130C>/whoIs [name] \c6- Displays all the players with names or character names matching the input.');
  698.     messageClient(%this, '', '<color:A6130C>/event [text] \c6- Describes a global in-character event.');
  699.  
  700.     messageClient(%this, '', '\c6\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97');
  701.     messageClient(%this, '', '\c6Use the <color:A6130C>PageUp \c6and <color:A6130C>PageDown \c6keys to scroll (by default).');
  702. }
  703.  
  704. function serverCmdOOC(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15, %a16, %a17, %a18, %a19, %a20, %a21, %a22, %a23, %a24, %a25, %a26, %a27, %a28, %a29, %a30, %a31, %a32)
  705. { //Check if the OOC is muted.
  706.     if ($oocmute == 1)
  707.     {
  708.         if (!%this.isAdmin)
  709.         {
  710.             continue;
  711.         }
  712.         messageClient("\c3The OOC is disabled!");
  713.     }
  714.     else if($mute[%this] = 1)
  715.     {
  716.         messageClient("\c3You are muted!");
  717.         return;
  718.     }
  719.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["ooc"] <= $RoleplayServer::Timeout["OOC"])
  720.     {
  721.         %secondsLeft = mCeil(($RoleplayServer::Timeout["OOC"] - (getSimTime() - %this.lastCommandUse["ooc"])) / 1000);
  722.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to use OOC again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  723.         return;
  724.     }
  725.    
  726.     %this.lastCommandUse["ooc"] = getSimTime();
  727.  
  728.     %msg = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20 SPC %a21 SPC %a22 SPC %a23 SPC %a24 SPC %a25 SPC %a26 SPC %a27 SPC %a28 SPC %a29 SPC %a30 SPC %a31 SPC %a32);
  729.     %msg = StripMLControlChars(%msg);
  730.  
  731.     %msg = strreplace(%msg, "https://", "http://");
  732.  
  733.     if(strpos(%msg, "http://") == 0)
  734.     {
  735.         %msg = getSubStr(%msg, 7, strlen(%msg) - 7);
  736.         %link = firstWord(%msg);
  737.         %rest = restWords(%msg);
  738.  
  739.         %msg = trim("<a:" @ %link @ ">" @ %link @ "</a>" SPC %rest);
  740.     }
  741.  
  742.     if(%msg $= "")
  743.     {
  744.         return;
  745.     }
  746.  
  747.     messageAll('', '%1<color:A6130C>[OOC] \c6%2<color:DDDDDD>: %3', "<bitmap:Add-Ons/Server_Roleplay/res/icons/" @ %this.getUserIcon() @ "> ", %this.getPlayerName(), %msg);
  748.     serverPlay2D(RoleplayChatSound);
  749.  
  750.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") via OOC '" @ %msg @ "'", "\c1");
  751. }
  752.  
  753. function serverCmdLOOC(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15, %a16, %a17, %a18, %a19, %a20, %a21, %a22, %a23, %a24, %a25, %a26, %a27, %a28, %a29, %a30, %a31, %a32)
  754. {
  755.     if(!isObject(%this.player))
  756.     {
  757.         return;
  758.     }
  759.     else if(%this.roleplayName $= "")
  760.     {
  761.         //Warn people who have no character name.
  762.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have a character name. Type /rpHelp.');
  763.         return;
  764.     }
  765.  
  766.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["looc"] <= $RoleplayServer::Timeout["LOOC"])
  767.     {
  768.         %secondsLeft = mCeil(($RoleplayServer::Timeout["LOOC"] - (getSimTime() - %this.lastCommandUse["looc"])) / 1000);
  769.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to use LOOC again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  770.         return;
  771.     }
  772.    
  773.     %this.lastCommandUse["looc"] = getSimTime();
  774.  
  775.     %msg = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20 SPC %a21 SPC %a22 SPC %a23 SPC %a24 SPC %a25 SPC %a26 SPC %a27 SPC %a28 SPC %a29 SPC %a30 SPC %a31 SPC %a32);
  776.     %msg = StripMLControlChars(%msg);
  777.  
  778.     if(%msg $= "")
  779.     {
  780.         return;
  781.     }
  782.  
  783.     %pos = %this.player.getPosition();
  784.  
  785.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  786.     {
  787.         %client = ClientGroup.getObject(%i);
  788.  
  789.         if(!isObject(%client.player))
  790.             continue;
  791.  
  792.         if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["LOOC"])
  793.         {
  794.             messageClient(%client, '', '<color:A6130C>[LOOC] <color:F8D690>%1: %2', %client.getOtherCharacterName(%this), %msg);
  795.             %client.play2D(RoleplayChatSound);
  796.         }
  797.     }
  798.  
  799.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") via LOOC '" @ %msg @ "'", "\c1");
  800. }
  801.  
  802. function serverCmdAdminChat(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15, %a16, %a17, %a18, %a19, %a20, %a21, %a22, %a23, %a24, %a25, %a26, %a27, %a28, %a29, %a30, %a31, %a32)
  803. {
  804.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["ac"] <= $RoleplayServer::Timeout["AdminChat"])
  805.     {
  806.         %secondsLeft = mCeil(($RoleplayServer::Timeout["AdminChat"] - (getSimTime() - %this.lastCommandUse["ac"])) / 1000);
  807.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to report again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  808.         return;
  809.     }
  810.  
  811.     %this.lastCommandUse["ac"] = getSimTime();
  812.  
  813.     %msg = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20 SPC %a21 SPC %a22 SPC %a23 SPC %a24 SPC %a25 SPC %a26 SPC %a27 SPC %a28 SPC %a29 SPC %a30 SPC %a31 SPC %a32);
  814.     %msg = StripMLControlChars(%msg);
  815.  
  816.     if(%msg $= "")
  817.     {
  818.         return;
  819.     }
  820.  
  821.     if(!%this.isAdmin) // Handle it as a report.
  822.     {
  823.         %foundOne = false;
  824.  
  825.         for(%i = 0; %i < ClientGroup.getCount(); %i++)
  826.         {
  827.             %client = ClientGroup.getObject(%i);
  828.  
  829.             if(%client.isAdmin || %client == %this)
  830.             {
  831.                 messageClient(%client, '', '%1<color:A6130C>[Report] \c6%2<color:33DDDD>: %3', "<bitmap:Add-Ons/Server_Roleplay/res/icons/" @ %this.getUserIcon() @ "> ", %this.getPlayerName(), %msg);
  832.                 %client.play2D(RoleplayChatSound);
  833.  
  834.                 if(%client.isAdmin)
  835.                     %foundOne = true;
  836.             }
  837.         }
  838.  
  839.         if(!%foundOne)
  840.         {
  841.             messageClient(%this, '', '\c6No admins were online to hear your report!');
  842.         }
  843.  
  844.         RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") reports '" @ %msg @ "'", "\c1");
  845.     }
  846.     else // Handle it as admin-chat.
  847.     {
  848.         for(%i = 0; %i < ClientGroup.getCount(); %i++)
  849.         {
  850.             %client = ClientGroup.getObject(%i);
  851.  
  852.             if(%client.isAdmin)
  853.             {
  854.                 messageClient(%client, '', '%1<color:A6130C>[Admin Chat] \c6%2<color:33DDDD>: %3', "<bitmap:Add-Ons/Server_Roleplay/res/icons/" @ %this.getUserIcon() @ "> ", %this.getPlayerName(), %msg);
  855.                 %client.play2D(RoleplayChatSound);
  856.             }
  857.         }
  858.  
  859.         RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") via admin chat '" @ %msg @ "'", "\c1");
  860.     }
  861. }
  862.  
  863. function serverCmdMe(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15, %a16, %a17, %a18, %a19, %a20, %a21, %a22, %a23, %a24, %a25, %a26, %a27, %a28, %a29, %a30, %a31, %a32)
  864. {
  865.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["me"] <= $RoleplayServer::Timeout["Talking"])
  866.     {
  867.         %secondsLeft = mCeil(($RoleplayServer::Timeout["Talking"] - (getSimTime() - %this.lastCommandUse["me"])) / 1000);
  868.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to perform again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  869.         return;
  870.     }
  871.    
  872.     %this.lastCommandUse["me"] = getSimTime();
  873.  
  874.     %player = %this.player;
  875.  
  876.     if(!isObject(%player))
  877.     {
  878.         return;
  879.     }
  880.     else if(%this.roleplayName $= "")
  881.     {
  882.         //Warn people who have no character name.
  883.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have a character name. Type /rpHelp.');
  884.         return;
  885.     }
  886.  
  887.     %msg = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20 SPC %a21 SPC %a22 SPC %a23 SPC %a24 SPC %a25 SPC %a26 SPC %a27 SPC %a28 SPC %a29 SPC %a30 SPC %a31 SPC %a32);
  888.     %msg = StripMLControlChars(%msg);
  889.  
  890.     if(%msg $= "")
  891.     {
  892.         return;
  893.     }
  894.  
  895.     %pos = %player.getPosition();
  896.  
  897.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  898.     {
  899.         %client = ClientGroup.getObject(%i);
  900.  
  901.         if(!isObject(%client.player))
  902.             continue;
  903.  
  904.         if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["Talking"])
  905.         {
  906.             messageClient(%client, '', '<color:F8D690>** %1 %2', %client.getOtherCharacterName(%this), %msg);
  907.             %client.play2D(RoleplayChatSound);
  908.         }
  909.     }
  910.  
  911.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/me " @ %msg @ "'");
  912. }
  913.  
  914. function serverCmdIt(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15, %a16, %a17, %a18, %a19, %a20, %a21, %a22, %a23, %a24, %a25, %a26, %a27, %a28, %a29, %a30, %a31, %a32)
  915. {
  916.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["it"] <= $RoleplayServer::Timeout["Talking"])
  917.     {
  918.         %secondsLeft = mCeil(($RoleplayServer::Timeout["Talking"] - (getSimTime() - %this.lastCommandUse["it"])) / 1000);
  919.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to perform again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  920.         return;
  921.     }
  922.    
  923.     %this.lastCommandUse["it"] = getSimTime();
  924.  
  925.     %player = %this.player;
  926.  
  927.     if(!isObject(%player))
  928.     {
  929.         return;
  930.     }
  931.     else if(%this.roleplayName $= "")
  932.     {
  933.         //Warn people who have no character name.
  934.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have a character name. Type /rpHelp.');
  935.         return;
  936.     }
  937.  
  938.     %msg = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20 SPC %a21 SPC %a22 SPC %a23 SPC %a24 SPC %a25 SPC %a26 SPC %a27 SPC %a28 SPC %a29 SPC %a30 SPC %a31 SPC %a32);
  939.     %msg = StripMLControlChars(%msg);
  940.  
  941.     if(%msg $= "")
  942.     {
  943.         return;
  944.     }
  945.  
  946.     %pos = %player.getPosition();
  947.  
  948.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  949.     {
  950.         %client = ClientGroup.getObject(%i);
  951.  
  952.         if(!isObject(%client.player))
  953.             continue;
  954.  
  955.         if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["Talking"])
  956.         {
  957.             messageClient(%client, '', '<color:F8D690>** %1', %msg);
  958.             %client.play2D(RoleplayChatSound);
  959.         }
  960.     }
  961.  
  962.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/it " @ %msg @ "'");
  963. }
  964.  
  965. function serverCmdW(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15, %a16, %a17, %a18, %a19, %a20, %a21, %a22, %a23, %a24, %a25, %a26, %a27, %a28, %a29, %a30, %a31, %a32)
  966. {
  967.     if(!isObject(%this.player))
  968.     {
  969.         return;
  970.     }
  971.     else if(%this.roleplayName $= "")
  972.     {
  973.         //Warn people who have no character name.
  974.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have a character name. Type /rpHelp.');
  975.         return;
  976.     }
  977.  
  978.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["w"] <= $RoleplayServer::Timeout["Talking"])
  979.     {
  980.         %secondsLeft = mCeil(($RoleplayServer::Timeout["Talking"] - (getSimTime() - %this.lastCommandUse["w"])) / 1000);
  981.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to whisper again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  982.         return;
  983.     }
  984.    
  985.     %this.lastCommandUse["w"] = getSimTime();
  986.  
  987.     %msg = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20 SPC %a21 SPC %a22 SPC %a23 SPC %a24 SPC %a25 SPC %a26 SPC %a27 SPC %a28 SPC %a29 SPC %a30 SPC %a31 SPC %a32);
  988.     %msg = StripMLControlChars(%msg);
  989.  
  990.     if(%msg $= "")
  991.     {
  992.         return;
  993.     }
  994.  
  995.  
  996.     %pos = %this.player.getPosition();
  997.  
  998.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  999.     {
  1000.         %client = ClientGroup.getObject(%i);
  1001.  
  1002.         if(!isObject(%client.player))
  1003.             continue;
  1004.  
  1005.         if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["Whispering"])
  1006.         {
  1007.             messageClient(%client, '', '<color:F8D690>%1 (Whisper): "%2"', %client.getOtherCharacterName(%this), %msg);
  1008.             %client.play2D(RoleplayChatSound);
  1009.         }
  1010.     }
  1011.  
  1012.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/w " @ %msg @ "'");
  1013. }
  1014.  
  1015. function serverCmdY(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15, %a16, %a17, %a18, %a19, %a20, %a21, %a22, %a23, %a24, %a25, %a26, %a27, %a28, %a29, %a30, %a31, %a32)
  1016. {
  1017.     if(!isObject(%this.player))
  1018.     {
  1019.         return;
  1020.     }
  1021.     else if(%this.roleplayName $= "")
  1022.     {
  1023.         //Warn people who have no character name.
  1024.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have a character name. Type /rpHelp.');
  1025.         return;
  1026.     }
  1027.  
  1028.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["y"] <= $RoleplayServer::Timeout["Talking"])
  1029.     {
  1030.         %secondsLeft = mCeil(($RoleplayServer::Timeout["Talking"] - (getSimTime() - %this.lastCommandUse["y"])) / 1000);
  1031.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to yell again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  1032.         return;
  1033.     }
  1034.    
  1035.     %this.lastCommandUse["y"] = getSimTime();
  1036.  
  1037.     %msg = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20 SPC %a21 SPC %a22 SPC %a23 SPC %a24 SPC %a25 SPC %a26 SPC %a27 SPC %a28 SPC %a29 SPC %a30 SPC %a31 SPC %a32);
  1038.     %msg = StripMLControlChars(%msg);
  1039.  
  1040.     if(%msg $= "")
  1041.     {
  1042.         return;
  1043.     }
  1044.  
  1045.     %pos = %this.player.getPosition();
  1046.  
  1047.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  1048.     {
  1049.         %client = ClientGroup.getObject(%i);
  1050.  
  1051.         if(!isObject(%client.player))
  1052.             continue;
  1053.  
  1054.         if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["Yelling"])
  1055.         {
  1056.             messageClient(%client, '', '<color:F8D690>%1 (Yell): "%2"', %client.getOtherCharacterName(%this), %msg);
  1057.             %client.play2D(RoleplayChatSound);
  1058.         }
  1059.     }
  1060.  
  1061.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/y " @ %msg @ "'");
  1062. }
  1063.  
  1064. function serverCmdRoll(%this, %max)
  1065. {
  1066.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["roll"] <= $RoleplayServer::Timeout["Roll"])
  1067.     {
  1068.         %secondsLeft = mCeil(($RoleplayServer::Timeout["Roll"] - (getSimTime() - %this.lastCommandUse["roll"])) / 1000);
  1069.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to roll again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  1070.         return;
  1071.     }
  1072.    
  1073.     %this.lastCommandUse["roll"] = getSimTime();
  1074.  
  1075.     %player = %this.player;
  1076.  
  1077.     if(!isObject(%player))
  1078.     {
  1079.         return;
  1080.     }
  1081.     else if(%this.roleplayName $= "")
  1082.     {
  1083.         //Warn people who have no character name.
  1084.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have a character name. Type /rpHelp.');
  1085.         return;
  1086.     }
  1087.  
  1088.     %max = mClamp(%max, 1, 9999);
  1089.  
  1090.     %rand = getRandom(%max);
  1091.  
  1092.     %pos = %player.getPosition();
  1093.  
  1094.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  1095.     {
  1096.         %client = ClientGroup.getObject(%i);
  1097.  
  1098.         if(!isObject(%client.player))
  1099.             continue;
  1100.  
  1101.         if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["Talking"])
  1102.         {
  1103.             messageClient(%client, '', '<color:800080>** %1 has rolled %2 out of %3', %client.getOtherCharacterName(%this), %rand, %max);
  1104.             %client.play2D(RoleplayChatSound);
  1105.         }
  1106.     }
  1107.  
  1108.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/roll " @ %max @ "'");
  1109. }
  1110.  
  1111. function getSafeRoleplayName(%this)
  1112. {
  1113.     %this = StripMLControlChars(%this);
  1114.  
  1115.     %this = strreplace(%this, "[", "");
  1116.     %this = strreplace(%this, "]", "");
  1117.     %this = strreplace(%this, "{", "");
  1118.     %this = strreplace(%this, "}", "");
  1119.     %this = strreplace(%this, "(", "");
  1120.     %this = strreplace(%this, ")", "");
  1121.     %this = strreplace(%this, "_", "");
  1122.  
  1123.     return %this;
  1124. }
  1125.  
  1126. function serverCmdSetName(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
  1127. {
  1128.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["setName"] <= $RoleplayServer::Timeout["SetName"])
  1129.     {
  1130.         %secondsLeft = mCeil(($RoleplayServer::Timeout["SetName"] - (getSimTime() - %this.lastCommandUse["setName"])) / 1000);
  1131.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to set your name again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  1132.         return;
  1133.     }
  1134.  
  1135.     %this.lastCommandUse["setName"] = getSimTime();
  1136.  
  1137.     %name = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10);
  1138.     %name = getSubStr(%name, 0, 42);
  1139.     %name = getSafeRoleplayName(%name);
  1140.  
  1141.     if(strlwr(%name) $= "somebody")
  1142.     {
  1143.         messageClient(%this, '', "\c6Nice try. You can't set your name to 'somebody'.");
  1144.         return;
  1145.     }
  1146.  
  1147.     %this.roleplayName = %name;
  1148.  
  1149.     messageClient(%this, '', '\c6You have set your roleplay name to \c6%1\c6.', %this.roleplayName);
  1150.  
  1151.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/setName " @ %name @ "'", "\c5");
  1152. }
  1153.  
  1154. function serverCmdSetFreq(%this, %freq)
  1155. {
  1156.     if(!isObject(%this.player))
  1157.     {
  1158.         return;
  1159.     }
  1160.     else if(%this.roleplayName $= "")
  1161.     {
  1162.         //Warn people who have no character name.
  1163.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have a character name. Type /rpHelp.');
  1164.         return;
  1165.     }
  1166.  
  1167.     %image = %this.player.getMountedImage(0);
  1168.  
  1169.     if(!isObject(%image) || %image.getName() !$= "RadioImage")
  1170.     {
  1171.         messageClient(%this, '', "\c6You must be holding a radio.");
  1172.         return;
  1173.     }
  1174.  
  1175.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["setFreq"] <= $RoleplayServer::Timeout["SetFreq"])
  1176.     {
  1177.         %secondsLeft = mCeil(($RoleplayServer::Timeout["SetFreq"] - (getSimTime() - %this.lastCommandUse["setFreq"])) / 1000);
  1178.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to set your frequency again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  1179.         return;
  1180.     }
  1181.  
  1182.     %this.lastCommandUse["setFreq"] = getSimTime();
  1183.  
  1184.     %freq = mFloatLength(%freq, 1);
  1185.  
  1186.     if(%freq < 88)
  1187.     {
  1188.         messageClient(%this, '', '\c6The frequency must be higher than 88.');
  1189.         return;
  1190.     }
  1191.  
  1192.     if(%freq > 188)
  1193.     {
  1194.         messageClient(%this, '', '\c6The frequency must be lower than 188.');
  1195.         return;
  1196.     }
  1197.  
  1198.     %this.radioFrequency = %freq;
  1199.     messageClient(%this, '', '\c6You have set your radio\'s frequency to \c6%1\c6.', %this.radioFrequency);
  1200.  
  1201.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/setFreq " @ %freq @ "'");
  1202. }
  1203.  
  1204. function serverCmdWho(%this)
  1205. {
  1206.     if(!isObject(%this.player))
  1207.     {
  1208.         return;
  1209.     }
  1210.  
  1211.     if(!%this.isAdmin)
  1212.     {
  1213.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have access to that command, %1.', %this.getPlayerName());
  1214.         %obj.client.play2D(RoleplayChatSound);
  1215.         return;
  1216.     }
  1217.  
  1218.     messageClient(%this, '', '\c6Players within yelling distance:');
  1219.  
  1220.     %pos = %this.player.getPosition();
  1221.  
  1222.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  1223.     {
  1224.         %client = ClientGroup.getObject(%i);
  1225.    
  1226.         if(!isObject(%client.player))
  1227.             continue;
  1228.    
  1229.         %dist = VectorDist(%client.player.getPosition(), %pos);
  1230.  
  1231.         if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["Yelling"])
  1232.         {
  1233.             %foundOne = true;
  1234.             messageClient(%this, '', '\c6\xbb \c6%1 \c6(%2m)', %client.getPlayerName(), %dist);
  1235.         }
  1236.     }
  1237.  
  1238.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/who'");
  1239. }
  1240.  
  1241. function serverCmdWhoIs(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
  1242. {
  1243.     if(!%this.isAdmin)
  1244.     {
  1245.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have access to that command, %1.', %this.getPlayerName());
  1246.         %obj.client.play2D(RoleplayChatSound);
  1247.         return;
  1248.     }
  1249.  
  1250.     %name = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10);
  1251.     %name = StripMLControlChars(%name);
  1252.  
  1253.     %foundOne = false;
  1254.  
  1255.     messageClient(%this, '', '\c6Players matching \'\c6%1\c6\':', %name);
  1256.  
  1257.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  1258.     {
  1259.         %client = ClientGroup.getObject(%i);
  1260.  
  1261.         if(strpos(strlwr(%client.roleplayName), strlwr(%name)) > -1)
  1262.         {
  1263.             messageClient(%this, '', '\c6\xbb \c6%1 \c6is the character of \c6%2\c6.', %client.roleplayName, %client.getPlayerName());
  1264.             %foundOne = true;
  1265.         }
  1266.         if(strpos(strlwr(%client.getPlayerName()), strlwr(%name)) > -1)
  1267.         {
  1268.             messageClient(%this, '', '\c6\xbb \c6%1\c6\'s character is \c6%2\c6.', %client.getPlayerName(), %client.roleplayName);
  1269.             %foundOne = true;
  1270.         }
  1271.     }
  1272.  
  1273.     if(!%foundOne)
  1274.     {
  1275.         messageClient(%this, '', '\c6No players found with that character name or username.');
  1276.     }
  1277.  
  1278.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/whoIs " @ %name @ "'");
  1279. }
  1280.  
  1281. function serverCmdEvent(%this, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13, %a14, %a15, %a16, %a17, %a18, %a19, %a20, %a21, %a22, %a23, %a24, %a25, %a26, %a27, %a28, %a29, %a30, %a31, %a32)
  1282. {
  1283.     if(!%this.isAdmin)
  1284.     {
  1285.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have access to that command, %1.', %this.getPlayerName());
  1286.         %obj.client.play2D(RoleplayChatSound);
  1287.         return;
  1288.     }
  1289.  
  1290.     %msg = trim(%a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20 SPC %a21 SPC %a22 SPC %a23 SPC %a24 SPC %a25 SPC %a26 SPC %a27 SPC %a28 SPC %a29 SPC %a30 SPC %a31 SPC %a32);
  1291.     %msg = StripMLControlChars(%msg);
  1292.  
  1293.     if(%msg $= "")
  1294.     {
  1295.         return;
  1296.     }
  1297.  
  1298.     %pos = %player.getPosition();
  1299.  
  1300.     for(%i = 0; %i < ClientGroup.getCount(); %i++)
  1301.     {
  1302.         %client = ClientGroup.getObject(%i);
  1303.  
  1304.         if(!isObject(%client.player))
  1305.             continue;
  1306.  
  1307.         if(VectorDist(%client.player.getPosition(), %pos) <= $RoleplayServer::Radius["Talking"])
  1308.         {
  1309.             messageClient(%client, '', '<color:F8D690>** %1', %msg);
  1310.             %client.play2D(RoleplayChatSound);
  1311.         }
  1312.     }
  1313.  
  1314.     messageAll('', '<color:DD6600>%1', %msg);
  1315.     serverPlay2D(RoleplayChatSound);
  1316.  
  1317.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/event " @ %msg @ "'");
  1318. }
  1319.  
  1320. function gameConnection::getOtherCharacterName(%this, %client)
  1321. {
  1322.     if(%this == %client || %this.recognizes[%client.getBLID(), %client.roleplayName])
  1323.     {
  1324.         return %client.roleplayName;
  1325.     }
  1326.  
  1327.     return "Somebody";
  1328. }
  1329.  
  1330. function serverCmdRecognize(%this)
  1331. {
  1332.     if(!isObject(%this.player))
  1333.     {
  1334.         return;
  1335.     }
  1336.     else if(%this.roleplayName $= "")
  1337.     {
  1338.         //Warn people who have no character name.
  1339.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>You do not have a character name. Type /rpHelp.');
  1340.         return;
  1341.     }
  1342.  
  1343.     if(!%this.isAdmin && getSimTime() - %this.lastCommandUse["recognize"] <= $RoleplayServer::Timeout["Recognize"])
  1344.     {
  1345.         %secondsLeft = mCeil(($RoleplayServer::Timeout["Recognize"] - (getSimTime() - %this.lastCommandUse["recognize"])) / 1000);
  1346.         messageClient(%this, '', '<bitmap:Add-Ons/Server_Roleplay/res/icons/comment> <color:DDDDFF>Please wait %1 second%2 to recognize yourself again.', %secondsLeft, %secondsLeft == 1 ? "" : "s");
  1347.         return;
  1348.     }
  1349.  
  1350.     %this.lastCommandUse["recognize"] = getSimTime();
  1351.  
  1352.     //$RoleplayServer::Radius["Recognize"]
  1353.     initContainerRadiusSearch(%this.player.getPosition(), $RoleplayServer::Radius["Recognize"], $Typemasks::PlayerObjectType);
  1354.  
  1355.     while(%obj = containerSearchNext())
  1356.     {
  1357.         if(%obj == %this.player)
  1358.             continue;
  1359.  
  1360.         if(!isObject(%obj.client))
  1361.             continue;
  1362.  
  1363.         if(%obj.client.recognizes[%this.getBLID(), %this.roleplayName])
  1364.             continue;
  1365.  
  1366.         messageClient(%obj.client, '', '<color:F8D690>You now recognize %1.', %this.roleplayName);
  1367.         %obj.client.play2D(RoleplayChatSound);
  1368.         %obj.client.recognizes[%this.getBLID(), %this.roleplayName] = true;
  1369.     }
  1370.  
  1371.     messageClient(%this, '', '<color:F8D690>People within a %1 stud radius now recognize your name.', $RoleplayServer::Radius["Recognize"]);
  1372.     %this.play2D(RoleplayChatSound);
  1373.  
  1374.     RS_Log(%this.getPlayerName() SPC "(" @ %this.getBLID() @ ") used '/recognize'");
  1375. }
  1376.  
  1377. function getRandomNamedBrick(%group, %name)
  1378. {
  1379.     %name = "_" @ %name;
  1380.  
  1381.     for(%a = 0; %a < %group.NTNameCount; %a++)
  1382.     {
  1383.         if(%group.NTName[%a] !$= %name || %group.NTObjectCount[%name] < 0)
  1384.         {
  1385.             continue;
  1386.         }
  1387.  
  1388.         %n = %group.NTObjectCount[%name];
  1389.  
  1390.         return %group.NTObject[%name, getRandom(0, %n - 1)];
  1391.     }
  1392.  
  1393.     return 0;
  1394. }
  1395.  
  1396. registerOutputEvent("fxDTSBrick", "doRoleplayItem", "string 200 100" TAB "int 1 60 30");
  1397.  
  1398. function fxDTSBrick::doRoleplayItem(%this, %name, %time)
  1399. {
  1400.     %target = getRandomNamedBrick(%this.getGroup(), %name);
  1401.  
  1402.     if(!isObject(%target))
  1403.     {
  1404.         return;
  1405.     }
  1406.  
  1407.     %items = 0;
  1408.  
  1409.     for(%i = 0; %i < %target.getNumUpBricks(); %i++)
  1410.     {
  1411.         %brick = %target.getUpBrick(%i);
  1412.  
  1413.         if(isObject(%brick.item))
  1414.         {
  1415.             %item[%items] = %brick.item.getDatablock();
  1416.             %items++;
  1417.         }
  1418.     }
  1419.  
  1420.     if(!%items)
  1421.     {
  1422.         return;
  1423.     }
  1424.  
  1425.     %chosen = %item[getRandom(0, %items - 1)];
  1426.  
  1427.     if(isObject(%chosen))
  1428.     {
  1429.         %popTime = $Game::Item::PopTime;
  1430.  
  1431.         $Game::Item::PopTime = %time * 1000;
  1432.  
  1433.         %this.spawnItem("0 0 2", %chosen);
  1434.  
  1435.         $Game::Item::PopTime = %popTime;
  1436.     }
  1437. }
  1438.  
  1439. // Admin client handshake.
  1440. function serverCmdRPA_Handshake(%this)
  1441. {
  1442.     %this.hasRPA = true;
  1443. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement