Author Topic: issue with randomizer script (not mine)  (Read 482 times)

brian smith gave me a randomizer script and we tried a few things but it still doesn't work for me. The console doesn't show any errors regarding the script.

Code: [Select]
$TTList = "";
function Player::addItem(%player,%image,%client)
{
   for(%i = 0; %i < %player.getDatablock().maxTools; %i++)
   {
      %tool = %player.tool[%i];
      if(%tool == 0)
      {
         %player.tool[%i] = %image;
         %player.weaponCount++;
         messageClient(%client,'MsgItemPickup','',%i,%image);
         break;
      }
   }
}
function initTTList() {
        for( %i=0; %i < datablockGroup.getCount(); %i++ ) {
                %obj = datablockGroup.getObject( %i );
                if( %obj.getClassName() $= "ItemData" ) {
                                $TTList = trim( $TTList SPC %obj.getID() );
                }
        }
}
 
function Player::getRandomWeapon(%player) {
        %weapon = getWord( $TTList, getRandom( 0, getWordCount($TTList) - 1 ) );
 
        %player.addItem( %weapon );
}
 
package TTGiveItem {
        function gameConnection::spawnPlayer( %client ) {
                %res = parent::spawnPlayer( %client );
                if( $TTList $= "" )
                        initTTList();
 
                if( isObject( %player = %client.player ) )
                        %player.getRandomWeapon();
 
                return %res;
        }
};
if( isPackage( TTGiveItem ) )
        deactivatePackage( TTGiveItem );
activatepackage( TTGiveItem );

can you guys find any errors?

"%player = %client.player"

That = doesn't look right. Aren't you supposed to use == when comparing? (And IIRC, = can be used to check if one thing CAN be set to another or something like that)

Oh wait, okay. Not comparison, but it still looks wrong. Try defining %player before the if structure, just incase.
« Last Edit: February 09, 2014, 03:26:57 PM by ThinkInvisible »

it's accurate
if((%variable = 1) == 1) == true

you can assign things during comparisons.. it's a good way to compact some code