item_nugget

Avatar
Spam Nugget
492 Posts
Posted Jan 04, 2012
Has anyone got item_nugget working?
Its an entity that, in conjunction with the script nugget_maker.nut, should award players points for collecting the nuggets.
But it doesnt work.
I have used nugget_maker.nut to spawn these at the correct points (info_targets) without any hassels by following the directions within the script.
But the function AwardNugget appears not to work. It either does not register the nugget being collected or does not do anything upon recieving that information.
The script is below:

//=========================================================
// This script is attached to a logic_script entity.  The  
// script should reference info_target entities that are 
// spawn destinations for nuggets.
// 
// EntityGroup[0] should point to the env_maker
// EntityGroup[1] should be the name of the spawn destinations
// EntityGroup[2] should point to the game_text entity
//=========================================================

// debugging
DBG <- 0

// number of available nuggets
number_of_nuggets <- 0

// number of nuggets awarded to player
AwardedNuggetCount <- 0

//---------------------------------------------------------
// OnPostSpawn
//---------------------------------------------------------
function OnPostSpawn()
{
   // array to contain list of spawn destinations for nuggets
   spawn_dest_array <- []
   local cur_ent = null
   
   // collect the number of nuggets to spawn
   do
   {
      // find info_target that is a spawn position for a nugget
      cur_ent = Entities.FindByClassname( cur_ent, "info_target" )   
      if ( cur_ent != null && cur_ent.GetName() == EntityGroup[1].GetName() )
      {
         number_of_nuggets++
         spawn_dest_array.append( cur_ent )
         if(DBG) printl("[VSCRIPT_DEBUG] appended " + number_of_nuggets + " " + cur_ent.GetName() + " to spawn_dest_array" ) 
      }
   } while ( cur_ent != null )
   
      
   if(DBG) printl( "[VSCRIPT_DEBUG] spawning " + number_of_nuggets + " nuggets." )
   
   // spawn the templates at the destination         
   for(local i=0; i<number_of_nuggets; i++)
   {         
      EntityGroup[0].SpawnEntityAtEntityOrigin(spawn_dest_array[i] )
      if(DBG) printl( "[VSCRIPT_DEBUG] spawning " + EntityGroup[0] + " at " + spawn_dest_array[i].GetName()  )
   }
}

//---------------------------------------------------------
// This function gets called when a nugget trigger is touched
//---------------------------------------------------------
function AwardNugget()
{
   AwardedNuggetCount++   
   if(DBG) printl("[VSCRIPT_DEBUG] You got " + AwardedNuggetCount + " of " + number_of_nuggets + " Aperture Incentivizing Nuggets!")
   EntFire( EntityGroup[2].GetName(), "settext", "You got " + AwardedNuggetCount + " of " + number_of_nuggets + " Aperture Incentivizing Nuggets!")    
   EntFire( EntityGroup[2].GetName(), "display" )
}

So am I doing something wrong? Is the script or entity broken? Can it be fixed?
Because it would be rather awesome if this works.
And yes, something similar could be done in hammer with the i/o system. But id rather have this work properly.

Advertisement
Registered users don’t see ads! Register now!
Avatar
ChickenMobile
2,460 Posts
Posted Jan 07, 2012
Replied 3 days later
I think there is a good reason why the script doesn't work, you need to reference the function when the nugget is picked up. Is there a 'OnPlayerPickup' output in the item_nugget?

Try putting "OnPlayerPickup" -> scriptnamehere -> "RunScriptCode" -> AwardNugget()

Avatar
Spam Nugget
492 Posts
Posted Jan 07, 2012
Replied 1 hour later
ahh okay i didnt realise i had to call the function, i dont have too much experience with code.
And nah, theres no onplayerpickup output :/ ill try using a trigger instead to call the function, that might work.
thanks!
Avatar
Lpfreaky90
2,842 Posts
Posted Jan 07, 2012
Replied 1 minutes later
if there isn't a onplayerpickup output just add it with smart edit disabled and see if it works? ^^
Advertisement
Registered users don’t see ads! Register now!
Avatar
Spam Nugget
492 Posts
Posted Jan 07, 2012
Replied 3 minutes later
ill give it a shot, thanks!