Jump to content

[HELP] Spawn-Protection: Keep Players from Getting Stuck.


UTurn

Recommended Posts

I wrote a spawn-protection script, it makes the player partially transparent so players know they're under spawn-protection. It also makes them unable to use weapons until they are no longer under spawn-protection, but it's missing one thing. I need to make it so that when a player is under spawn protection, there is no collision-detection when they intersect with another player.

When two players spawn at the same hospital at once, they get stuck in each other, how can I prevent this? I've seen other servers that allow you move right out of players who are standing on the spawnpoint. I saw an event named 'onPlayerContact', it might be useful but I don't know how to continue from there.

Would I handle this event, check if the 'currentElement' argument is another player, check if one of the players is spawn-protected and if so, cancel the event?

Here is what I'm working with:

hospitals_s.lua [server-Side]

  
... 
  
-- Spawns the player at the nearest hospital. 
function spawnAtHospital(thePlayer) 
    -- Spawn-protect the player for 8 seconds. 
    startSpawnProtection(thePlayer) 
     
    -- Spawn at the nearest hospital. 
    local xx,yy,zz,rr = findNearestHostpital(thePlayer) 
    spawnPlayer(thePlayer, xx,yy,zz,rr) 
    fadeCamera(thePlayer, true, 3.0) 
end 
  
-- Spawn-protect the player for 8 seconds. 
function startSpawnProtection(thePlayer) 
    -- Spawn-protect the player for 8 seconds. 
    setElementData(thePlayer, "spawnProtected", true) 
    setElementAlpha(thePlayer, 150) 
     
    setTimer( 
        function() 
            setElementData(thePlayer, "spawnProtected", false) 
            setElementAlpha(thePlayer, 255) 
             
            -- Load weapon and skin data. 
            if (SAVE_DATA[thePlayer]) then 
                setElementModel(thePlayer, SAVE_DATA[thePlayer].skin) 
                 
                if SAVE_DATA[thePlayer].weapons then 
                    for weapon, ammo in pairs (SAVE_DATA[thePlayer].weapons) do 
                        giveWeapon(thePlayer, weapon, ammo, true) 
                    end 
                end 
            end 
        end, 
        8000, 
        1 
    ) 
end 

hospitals_c.lua [Client-Side]

  
function onClientPlayerDamage(attacker, weapon, bodypart) 
    if (getElementData(localPlayer, "spawnProtected") == true) then 
        cancelEvent()    
    end 
end 
  
addEventHandler("onClientPlayerDamage", localPlayer, onClientPlayerDamage) 
  

Edited by Guest
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...