BriGhtx3 Posted May 28, 2011 Posted May 28, 2011 function schaden ( attacker, weapon, bodypart, loss ) if attacker then if getElementType ( attacker ) == "vehicle" then cancelEvent() else local player1 = getPlayerName(attacker) local player = getPlayerName(source) local spielzeit = getElementData(thePlayer, "PlayedH") local mindestzeit = 3 if tostring(spielzeit) < tostring(mindestzeit) then outputChatBox("Du kannst ihn nicht verletzen!", 255, 0, 0, attacker) outputChatBox("Du kannst nicht verletzt werden!", 255, 0, 0, player) setElementHealth(player, 100) setElementHealth(player, getElementHealth(player)-5) end end end end addEventHandler ( "onPlayerDamage", getRootElement(), schaden) What this script should do. It checks if the attacker or victim has played more than 3 hours and if not, the victim will get 100% health and the attacker -5. But it doesn't do. WARNING : BAD ARGUMENT @ GETELEMENTDATA The PlayedH is defined. Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
SDK Posted May 28, 2011 Posted May 28, 2011 You're mixing both player variables and sometimes even use their names (strings) where a player element is needed. function schaden ( attacker, weapon, bodypart, loss ) if attacker then if getElementType ( attacker ) == "vehicle" then cancelEvent() else local victim = source local spielzeit = getElementData(victim, "PlayedH") local mindestzeit = 3 if tostring(spielzeit) < tostring(mindestzeit) then outputChatBox("Du kannst ihn nicht verletzen!", 255, 0, 0, attacker) outputChatBox("Du kannst nicht verletzt werden!", 255, 0, 0, victim) setElementHealth(victim, 100) setElementHealth(attacker, getElementHealth(attacker)-5) end end end end addEventHandler ( "onPlayerDamage", getRootElement(), schaden) Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
BriGhtx3 Posted May 29, 2011 Author Posted May 29, 2011 Now just a part works. It doesn't matter whether you played less than 3 hours or not. The message outputs everytime. Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
Aibo Posted May 29, 2011 Posted May 29, 2011 why are you converting numbers to strings when comparing them? ?
SDK Posted May 29, 2011 Posted May 29, 2011 tostring -> tonumber and check your element data Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
Kenix Posted May 30, 2011 Posted May 30, 2011 addEventHandler ( "onPlayerDamage", root, function( attacker, weapon, bodypart, loss ) if attacker then if getElementType ( attacker ) == "vehicle" then cancelEvent() else local victim = source local spielzeit = getElementData(victim, "PlayedH") local mindestzeit = 3 if tonumber(spielzeit) < tonumber(mindestzeit) then outputChatBox("Du kannst ihn nicht verletzen!", 255, 0, 0, attacker) outputChatBox("Du kannst nicht verletzt werden!", 255, 0, 0, victim) setElementHealth(victim, 100) local health = getElementHealth(attacker) setElementHealth(attacker, health - 5) end end end end ) http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Moderators Citizen Posted June 3, 2011 Moderators Posted June 3, 2011 As far I know we can compare 2 strings. I mean for exemple this: if "a" < "b" then outputChatBox( "Yeah a it's lower than b !!" ) end And I think that you can make it for numbers, because it's compare the ASCII code. (If I'm wrong, tell me ) But yeah tonumber it's better. It checks if the attacker or victim has played more than 3 hours and if not, the victim will get 100% health and the attacker -5. If I understand correctly, the player have to play more than 3 hours before than he can killed by someone It's a spawn protect for 3 hours The rEvolution is coming ...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now