Editing RP_Chatmod, no syntax errors but it doesn't work regardless.

Author Topic: Editing RP_Chatmod, no syntax errors but it doesn't work regardless.  (Read 1644 times)

I tried to jump into this on my own, figuring I got enough knowledge in to do really basic things. But absolutely none of the things I've tried to implement work.

Some of the code is already in the RP-Chat mod.
Keep in mind I'm very very new to doing this, so a lot of it might look odd. If anyone could help fix these issues and explain how to do so/why these fixes do what, that will be awesome.

Quote
   function serverCmdwarn(%client, %target, %msg) //To warn players of their wrongdoing. Is the only command that worked. I planned to notify the person warning that their warn went through. (And I know how to do so.)
   {
      if (!%client.isAdmin)
         return;
      %target = findClientByName(%target);
      messageClient(%target, '', "\c3[You have been warned by \c6" @ %client.name @ "\c3 for ''\c6" @ %msg @ "\c3''\c3]");
      %timeswarned[%target] += 1;
   }

   function serverCmdtimeswarned(%client, %target, %timeswarned) //for admins to see how many times a player was warned.
   {
      if (!%client.isAdmin)
         return;
      %target = findClientByName(%target);
      messageClient("\c3" @ %target @ "\c6 has been warned \c3" @ %timeswarned[%target] @ "\c6 times.");
   }
   function serverCmdclearwarns(%client, %target, %timeswarned) //to clear the warnings a player has
   {
      if (!%client.isAdmin)
         return;
      %target = findClientByName(%target);
      %timeswarden[%target] = 0;
   }
   function serverCmdtoggleOOC(%client) //To turn off the OOC
   {
      if (!%client.isAdmin)
      {
         if (%oocmute = 1)
         {
            %oocmute = 0;
            announce("\c6The \c3OOC \c6has been disabled!");
         }
         else if (%oocmute = 0)
         {
            %oocmute = 1;
            announce("\c6The \c3OOC \c6has been enabled!");
         }
      }
      return;
   }
   function serverCmdMute(%client, %target) //To mute players from using the OOC
   {
      if (!%client.isAdmin)
         return;

      %target = findClientByName(%target);
      $isMuted[%target.bl_id] = true;
      messageClient(%target, '', "\c6You have been OOC muted by \c3" @ %client.name);
      echo(%client.name SPC "muted" SPC %target.name);
      messageClient(%client, '', "\c6You muted \c3" @ %target.name);
   }
   function serverCmdTeamMessageSent(%this, %msg) //Using the mute and toggle commands
   {
      if (%oocmute = 1)
      {
         messageClient("\c3The OOC is disabled!");
      }
      else
      {
         if (!%isMuted[%target.bl_id] = true)
         {
            messageClient("\c3You are muted!");
         }
         else
         {
            serverCmdOOC(%this, %msg);
         }
      }
   }

   function serverCmdMessageSent(%this, %msg) //again using the mute&toggle commands
   {
      if(!%this.hasSpawnedOnce || !isObject(%this.player))
      {
         //If they haven't spawned, OOC.
         if (%oocmute = 1)
         {
            messageClient("\c3The OOC is disabled!");
         }
         else
         {
            if (!%isMuted[%target.bl_id] = true)
            {
               messageClient("\c3You are muted!");
            }
            else
            {
               serverCmdOOC(%this, %msg);
            }
         }
         return;
      }
      //code continues here but with it's original purposes
      
      
   function ItemData::onPickup(%this, %obj, %user, %amount) //Trying to notify admins when people pickup items
   {
      Parent::onPickup(%this, %obj, %user, %amount);
      serverCmdAdminChat(%user @ "picked up an item!");
   }

   function Weapon::onPickup(%this, %obj, %player, %amount)
   {
      Parent::onPickup(%this, %obj, %player, %amount);
      serverCmdAdminChat(%user @ "picked up a weapon!");
   }

Put it in quotes for the //

Your main issue is not knowing which variable type to use.
With your warning system when you're accessing %timeswarned[%target] it isn't saving after the function ends. You need to use a global variable to keep track like this.

$variable = "something";
Variables that start with a $ are global variables and can be used anywhere.
%variable = "else";
These are local, after the function ends they end.


Another thing I noticed is that sometimes you're using = when you should be doing ==. The first one is the assignment operator so whenever you run code inside your if loops it's just going to set those variables to true. You want == to check if they're equal.

With your item pickup announcements, you're calling serverCmdAdminChat which expects a client as a parameter instead of just a message. When you type "/ac hello" the server gets serverCmdAdminChat(%yourClient, "hello"); so if you wanted to use it you'd need a client to send that is an admin. I'd suggest just making your own message admin command.

Only other thing I'd suggest is adding some error checking with your commands to make sure the target.
« Last Edit: December 17, 2017, 08:30:49 PM by Crøwn »


Not sure if this is right or not.




I hope this is in a Package

Your code:

function gameConnection::onClientEnterGame() //<- Missing arguments
{
     %target = findClientbyName(%target); //<- Invalid, you'd simply use the arguments passed from the function
     ....code....
     ................

It should look like this instead (notice the differences between the code below and your code above):

function gameConnection::onClientEnterGame(%this) //<- %this is the client AKA gameConnection (it's class), it can be named anything just be consistent
{
     //I dont understand what you're trying to do below but it's syntactically correct
     if($timesWarned[%this] < 1)
     {
          $timesWarned[%this] = 0;
     }
}

I hope this is in a Package
It is apart of one, indeed.

Thank you a lot for walking me through this.

I'm just beyond frustration at this point. Nothing is working regardless of making the fixes you've stated.
It even went ahead and called a piece of code I never touched to be a syntax error.


Here's the .cs; if anyone'd care to look and see why I'm not getting this right.
(90% of this is the original code. I put comments where I was editing it (two comments are from the original code aswell though))
https://pastebin.com/kvnmMFD9

The code you posted doesn't contain any syntax errors. My guess is that you're modifying a .cs file inside a zip. In order to execute an add-on inside a zip that has been modified you have to discoverFile() it. I suggest working in a folder until you're ready to release the add-on.

I haven't been experiencing syntax errors. Just nothing working flat out, but without errors. Though, the advice for how to edit
these in-game is awesome. So thanks :p

--EDIT--

I'm getting help from somebody in a 1 on 1 environment, like a class I guess, and it's helping solve the issues I'd been facing. Thanks for all your help, everyone.
« Last Edit: December 20, 2017, 10:41:26 PM by Doctor Disco »