Jump to content

Weapon kicker?!


xDrul

Recommended Posts

Hi,

I'm tryin' to script a 'weapon kicker', a script which allow me to kick players to another position by shooting him/her.. Great to get rid of dm'ers at roleplays / admin events etc etc :o. I've tied to script it several times but failed alot :D which codes should i use? onClientDamage/setElementPosition?? :o

All help much 'preciated!

Link to comment
you mean if admin shot to player will chane other position ?

Yeah, so i understand i should use getPlayerTeam & local team == ? :S And yep, so f.e. i shoot a bud with a M4 (or any other weapon(s), he will be 'kicked' warped to another position with setElementPosition)

Link to comment

change posX, posY, posZ to you'r Position you want

addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), 
    function (weapon, _, _, _, _, _, hitElement ) 
        if (getPlayerTeam ( localPlayer ) and getTeamName ( getPlayerTeam ( localPlayer ) ) == "Staff") then 
            if weapon == 31 and hitElement and getElementType(hitElement)=="player" then 
                 setElementPosition ( hitElement, posX, posY, posZ ) 
            end 
        end 
    end 
) 

Link to comment
change posX, posY, posZ to you'r Position you want
addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), 
    function (weapon, _, _, _, _, _, hitElement ) 
        if (getPlayerTeam ( localPlayer ) and getTeamName ( getPlayerTeam ( localPlayer ) ) == "Staff") then 
            if weapon == 31 and hitElement and getElementType(hitElement)=="player" then 
                 setElementPosition ( hitElement, posX, posY, posZ ) 
            end 
        end 
    end 
) 

This one doesnt work o.0

Link to comment

Either you're not using the code client-side or you didn't use M4 when testing. I removed the weapon ID so you can shoot them with any weapon.

Client-side

local posX, posY, posZ = 0, 0, 3 
  
addEventHandler("onClientPlayerWeaponFire", root, 
    function(weapon, _, _, _, _, _, hitElement) 
        if (getPlayerTeam(localPlayer) and getTeamName(getPlayerTeam(localPlayer)) == "Staff") then 
            if (hitElement) and (getElementType(hitElement) == "player") then 
                setElementPosition(hitElement, posX, posY, posZ) 
            end 
        end 
    end 
) 

Link to comment

This actually makes no sense. It should work. I have debugged it as far as I can and setting team and fetching team works server-side, but doesn't work on client-side. I guess this is a bug then, I'll report to Mantis unless I can find the reason.

Also, I made the synchronization work, the hit element should be moved away properly for all players now (not sure if it was the issue before, but just to make sure.

Here's a small workaround.

Client-side

addEventHandler("onClientPlayerWeaponFire", root, 
    function(weapon, _, _, _, _, _, hitElement) 
        if (getElementData(localPlayer, "players.team")) and (getElementData(localPlayer, "players.team") == "Staff") then 
            if (hitElement) and (getElementType(hitElement) == "player") then 
                triggerServerEvent("sendPlayerAway", hitElement) 
            end 
        end 
    end 
) 

Server-side

addEventHandler("onResourceStart", resourceRoot, 
    function() 
        for _,player in ipairs(getPlayersInTeam(getTeamFromName("Staff"))) do 
            setElementData(player, "players.team", "Staff", true) 
        end 
    end 
) 
  
local posX, posY, posZ = 0, 0, 3 
  
addEvent("sendPlayerAway", true) 
addEventHandler("sendPlayerAway", root, 
    function() 
        setElementPosition(source, posX, posY, posZ) 
    end 
) 

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...