Thread: [Tutorial] Random questions thread
View Single Post
Old 04-15-2012, 06:32 AM   #119   Add To Ignore List  
Werebull
 
NHunter's Avatar
 
Joined: Feb 2012
 
NHunter is offline
Default Re: Random questions thread

Quote:
Originally Posted by Finzy View Post
Just give me the code.

EDIT: It's alright, he helped me out on Steam. Thanks again.
If it's not too late, you may try something like this:

Code:
<...>
-- players : CPlayerPuppetEntity
-- player : CPlayerPuppetEntity
local players = worldInfo:GetAllPlayersInRange(entity, range)
for i = 1, #players
  local player = players[i]
  player:Teleport(destinationMarker, true)
end
<...>
Quote:
Originally Posted by Qynchou View Post
erm, i skimmed thru the thread so sorry if this was asked already

how do i make an enemy spawn when something is picked up/specific area is entered?
i already know how to simply spawn them but i got no idea how to make them spawn on pickups etc
also would like to know how to make secrets, as in message plays when you enter area/pickup something
thanks D:
This is really simple. for conditional spawning, you just need to create the right condition:
Code:
Wait(Event(detector.Activated)) // this is if you don't use RunHandled( ... ) construction in your script, or you need this trigger exactly inside some function. Do note that it may not always work, depending on the script and on what player does

On(Event(detector.Activated)) // this one is for outside-function conditions in RunHandled( ... ) construction or inside a function. Using it as a condition in simple scripts as a code-activator is not recommended as it often fires too early

On(/* All */ Any( EVENTLIST )) // if you need the event to be triggered by more than one object or event. EVENTLIST may either be a group event (e.g. Events( groupvariable.event )) or a list of simple events, separated by commas)

// weapon pickup trigger
Wait(Event(weapon.Picked))
// though I, personally, would recommend this construction - it has a broader range of ativators (e.g. it will fire even if you have full ammo for that weapon and the weapon itself)
Wait(Any(Event(weapon.Picked), Event(weapon.FailedPick)))

// whatever you need to happen after the trigger is fired, goes after the said trigger
// in case of simple trigger (I'm giving example with enemy spawning, but you may have anything else)
Wait(Any(Event(weapon.Picked), Event(weapon.FailedPick)))
  enemy:SpawnGroup()
// in case you're using RunHandled( ... ) construction, it'll be a bit more complex

RunHandled(
  function()[INDENT]WaitForever()
end,

On(Any(Event(weapon.Picked), Event(weapon.FailedPick))),
  function()
    enemy:SpawnGroup()
  end
)
As for tying secrets to detector areas or some entities, just set the secret as the target for that entity (Ctrl + Alt and click on the secret entity in editor). Do note that this might not work for the items that are spawned. you will have to use some more complex constructions there.

------------------------

EDIT:

If you need a secret-like message without actually having a secret (e.g. like on "Into the spider's nest", when you open the secret door for speedrun secret), you may use this scripting (I will have it based on item usage here, but may try it with some other events)

Code:
RunHandled(
-- useinfo : CUsedScriptEvent
-- player : CPlayerPuppetEntity

  function()
    item:EnableUsage()
    WaitForever()
  end,

On(Event(item.Used)),
  function(useinfo)
    local player = useinfo:GetUser()
    player:ShowMessageOnHUD("TTRS.message=Secret item used")
  end
)
ShowMessageOnHUD(string) function is the one used for showing 'secret found' messages, even if it is used implicitly through the Secret entity mechanisms
__________________
NHunter | NH | 夜狩猟家 | 灰色天使

Last edited by NHunter; 04-15-2012 at 05:37 PM.
  Reply With Quote