Jump to content

Weapon kicker?!


xDrul

Recommended Posts

Posted

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!

Posted
onClientPlayerWeaponFire

and

triggerServerEvent 
kickPlayer 

Doesnt kickPlayer kick the player out of the server? I actually ment the way to set their position to f.e. Las Vent. Cross. (so with setElementPosition(source, x, y, z, attacker) or idk :$

Posted
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)

Posted

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 
) 

Posted
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

Posted

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 
) 

Posted
StevyDK said:
@xDRul you must be in staff team first, myonlake code is working all what you have to do is changing the coordinates to the ones you want to you use.

Orly xD. I did, didn't work tho

Posted (edited)

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
Posted

Thanks alot! It worked! Just one small question left, can i also add smthg like outputChatBox('player who've been kicked' has been kicked by 'the attacker'") ? :D

Posted

Tfoe, i've tested it out with some friends.. They're able to kick me too (not in the Staff team) anyway to fix that? Besides that it works!

Posted
xDrul said:

Try it m8, i've copied & past exactly the same you posted ;)

I was more referring to the fact that everybody on your server are set to the admin team for a reason or another.

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