Jump to content

how to check if attacker ( at onClientPlayerDamage ) is...


Fabio(GNR)

Recommended Posts

how to check if attacker ( at onClientPlayerDamage ) is a player?

i have found the godmode script from solidsnake14 ( ty ) and edited it, to check for team... Everything works, except the last part, it will be triggered by onClientPlayerDamage and will first check if your in the right team, and then if the attacker is an player element, and if true it will cancel the damage, so it will only prevent damage when attacked by a player.

the whole code:

Server: function createTeamsOnStart () 
    teamfun = createTeam ( "Freeroaming Players", 0, 255, 0 ) 
    teamDM = createTeam ( "Deathmatching Players", 200, 0, 100 ) 
end 
  
function godnormal(playerSource) 
setPlayerTeam" class="kw6">setPlayerTeam" class="kw6">setPlayerTeam ( playerSource, teamfun ) 
end 
  
function normalgod(playerSource) 
setPlayerTeam" class="kw6">setPlayerTeam ( playerSource, teamDM ) 
end 
  
addCommandHandler ( "fun", godnormal ) 
addCommandHandler ( "dm", normalgod ) 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  )  
  
addCommandHandler("godmode", 
function (thePlayer) 
if getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam ( thePlayer ) == teamfun then 
triggerClientEvent(thePlayer,"god_mode",thePlayer) 
end 
end) 
  
  
Client: 
  
addEvent("god_mode",true) 
addEventHandler("god_mode",getRootElement(), function() addEventHandler ( "onClientPlayerDamage", getRootElement(), cancelalldamage ) end) 
  
function cancelalldamage (thePlayer)  
if getPlayerTeam" class="kw2">getPlayerTeam ( thePlayer ) == teamfun then  
cancelEvent()  
end 
  
function canceldamag ( playerSource, thePlayer, attacker, weapon, bodypart ) 
if getElementType ( attacker ) == "player" then 
if getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam ( thePlayer ) == teamfun then 
cancelEvent () 
            end 
     end 
end 
  
addEventHandler ( "onClientPlayerDamage", getRootElement(), canceldamag ) 
  
addEventHandler ( "onClientPlayerDamage", getRootElement(), canceldamag ) 
  
  
  
 

but the only problem is checking attacker it says: Bad arguments at line 38( the > in code )

EDIT: btw, it would be more useful, if godmode is only for 1 player... so how to like give a data to the player that typed the godmode command, and kinda create a group with players with that data, and only trigger for that group so instead of getRootElement() a group? Thanks

Edited by Guest
Link to comment

try this

Client:

  
addEvent("god_mode",true) 
addEventHandler("god_mode",getLocalPlayer(), function() addEventHandler ( "onClientPlayerDamage", getRootElement(), cancelalldamage ) end) 
  
function cancelalldamage (thePlayer)  
if getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam ( thePlayer ) == teamfun then  
cancelEvent()  
end 
  
function canceldamag ( playerSource, thePlayer, attacker, weapon, bodypart, loss ) 
if getElementType ( attacker ) == "player" then 
if getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam ( thePlayer ) == teamfun then 
cancelEvent () 
            end 
     end 
end 
  
addEventHandler ( "onClientPlayerDamage", getRootElement(), canceldamag ) 
  
  

Edited by Guest
Link to comment
try this

Client:

  
addEvent("god_mode",true) 
addEventHandler("god_mode",getRootElement(), function() addEventHandler ( "onClientPlayerDamage", getRootElement(), cancelalldamage ) end) 
  
function cancelalldamage (thePlayer)  
if getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam ( thePlayer ) == teamfun then  
cancelEvent()  
end 
  
function canceldamag ( playerSource, thePlayer, attacker, weapon, bodypart, loss ) 
if getElementType ( attacker ) == "player" then 
if getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam ( thePlayer ) == teamfun then 
cancelEvent () 
            end 
     end 
end 
  
addEventHandler ( "onClientPlayerDamage", getRootElement(), canceldamag ) 
  
  
 

What did you change? :P i will try anyway :P Outcome: gives the same error :S

EDIT: why does it show that kw2??

Link to comment
Read carefully.

hehe really cant find out what you changed, but what is the stuff with showing that class=k2 or something :S code doesnt work either sorry for not doing lua

EDIT: ok im really stupid lol, i fell testing my other part of script, and then saw the bad argument but thats logic cause there doesnt exist a "attacker" sorry to bother you with this :( but what about the saving data stuff ( in post1 edit )

EDIT2: ok im confused now, i tested it with my other pc so with attacker and it gave the same warning :/ the bad argument thing

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