Author Topic: An Event Restriction Question  (Read 927 times)

I am trying to make it so setting a bot weapon is admin only. For example- onbotattacked: bot: setweapon: Sniper Rifle. Right now this only works if an admin attacks the bot. I need this to work if a non admin attacks the bot too. Is there any way to set it so that just the brick owner must be admin or something like that?
Quote
function Player::setWeapon(%this, %item, %client)
{
   if(%client.isAdmin)
      {
      if(isObject(%this))
      {
         if(isObject(%image = %item.image))
         {
            %this.mountImage(%image, 0);
            if(%image.armReady)
            {
               %this.playThread(0, armReadyRight);
            }
         }
         else
         {
            %this.unmountImage(0);
            %this.playThread(0, root);
         }
      }
   }
}

function fxDTSbrick::setBotWeapon(%this, %item)
{
   if(isObject(%obj = %this.vehicle))
   {
      if(%obj.getClassName() $= "AIplayer")
      {
         %obj.setWeapon(%item);
      }
   }
}
Does anyone have a solution to this?

There's probably a %this.spawnbrick.client or something similar. Dig around for variables pertaining to that or make one.

This might not help, but VCE comes with the ifvalue isAdmin. Maybe you could look in there.

Hmm.. Still can't find a working solution to this. I was thinking that I need to replace
Quote
   if(%client.isAdmin)
with something but I don't know what.

Have you got a 1 appended to the end of your registering of the event? It wont append %client otherwise.

Have you got a 1 appended to the end of your registering of the event? It wont append %client otherwise.
Where do i add a 1? This is the bot events add-on in the outputs file if that helps you to explain where to put it.

There shoiuld be a line called RegisterOutputEvent();

Quote
registerOutputEvent("Player", "SetWeapon", "datablock itemData");
Yeah this is the line. I just don't know where to add the 1.
Also, will doing this solve my problem?

registerOutputEvent("Player", "SetWeapon", "datablock itemData",1);

you'll have to do something like this:

if(getBrickGroupfromObject(%brick).client.isAdmin)

however this will only work if the brick's owner is online and admin.

you'll have to do something like this:

if(getBrickGroupfromObject(%brick).client.isAdmin)

however this will only work if the brick's owner is online and admin.
When I do this it says in console:
Quote
ERROR: getBrickGroupfromObject() - "" is not an object
BackTrace: ->Player::setWeapon->getBrickGroupFromObject
However, I tested this with another event and it worked. =D
Any ideas why it will not work for this event?

Current code is this:
Quote
function Player::setWeapon(%this, %item, %client)
{
   if(getBrickGroupfromObject(%brick).client.isAdmin)
      {
      if(isObject(%this))
      {
         if(isObject(%image = %item.image))
         {
            %this.mountImage(%image, 0);
            if(%image.armReady)
            {
               %this.playThread(0, armReadyRight);
            }
         }
         else
         {
            %this.unmountImage(0);
            %this.playThread(0, root);
         }
      }
   }
}

function fxDTSbrick::setBotWeapon(%this, %item)
{
   if(isObject(%obj = %this.vehicle))
   {
      if(%obj.getClassName() $= "AIplayer")
      {
         %obj.setWeapon(%item);
      }
   }
}

The reason it doesn't find an object called %brick is because your function doesn't have a %brick in its input.

Quote
function Player::setWeapon(%this, %item, %client)  <- no %brick
{

}



to solve this problem on my server I changed my client and player functions into brick functions, and just grab the player from the %client through %client.player. so for example:

Quote
registerOutputEvent("fxDTSBrick", "setWeapon", "datablock ItemData");

function fxDTSBrick::setWeapon(%brick, %item, %client)
{
if(!isObject(%player = %client.player))
{
     return;  // just to be safe
}

             //function code goes here. you now have %brick, %player, %client and %item to work with.
}

the event will be listed under the brick(self) category in the event window

« Last Edit: December 13, 2009, 05:14:52 PM by [USSR] Diggy »

This must be a wierd problem because now the event works for admins again but still not for non admins.
Quote
function Player::setWeapon(%this, %item, %brick, %client)
{
   if(getBrickGroupfromObject(%brick).client.isAdmin)
      {
      if(isObject(%this))
      {
         if(isObject(%image = %item.image))
         {
            %this.mountImage(%image, 0);
            if(%image.armReady)
            {
               %this.playThread(0, armReadyRight);
            }
         }
         else
         {
            %this.unmountImage(0);
            %this.playThread(0, root);
         }
      }
   }
}

function fxDTSbrick::setBotWeapon(%this, %item)
{
   if(isObject(%obj = %this.vehicle))
   {
      if(%obj.getClassName() $= "AIplayer")
      {
         %obj.setWeapon(%item);
      }
   }
}