Entity.Respawn

From GMod Wiki

Revision as of 23:15, 27 September 2009 by Crazy Quebecer (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax Entity:Respawn( )
Description:
Re-spawns an entity. This is used to (Assumed) respawn broken objects, or reset the position of a prop to it's pre-spawn position like in Deathmatch.
Returns: nil
In Object: Entity
Realm: NewerServer.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Entity.Respawn]Entity.Respawn [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionEach time a weapon is picked up it will respawn moments later.
Used onNewerServer.png
Code
local nextclass, nextpos, nextang
 
local function RespawnTrigger(ply,wep)
    nextclass, nextpos, nextang = wep:GetClass(), wep:GetPos(), wep:GetAngles()
    wep:Respawn()   
    return(true)
end
 
hook.Add("PlayerCanPickupWeapon", "RespawnTrigger", RespawnTrigger)
 
hook.Add("OnEntityCreated","RespawnManagement",function(ent)
    if ent:IsWeapon() then
        local function DelayedRespawn(ent,class,model)
            if !(ent:GetClass() == class ) then return end
 
            nextclass = ""
 
            ent:SetPos(nextpos)
            ent:SetAngles(nextang)
 
        end
 
        timer.Simple(0.1,DelayedRespawn, ent,nextclass) -- The timer is needed so that the entity's class and model is properly defined.
    end
end)
 
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox