SkrillexX Posted May 20, 2013 Share Posted May 20, 2013 in this script , i'd like to give 25 health to each player who hits the specified marker . when the player hits the marker , he must do /mk to get 25 health , that's if he got 1500$ at least since he will loose them after buying the health. i'd like to know why this script does not work. ik marker locations are put as "x y z" but i changed that while testing. clientside : addEventHandler ("OnResourceStart") function medicKit local theMarker = createMarker ( x, y, z, "cylinder", 0 255 0 ) end function MarkerHit outputChatBox ("Type /mk to buy 25% of Health") end addEventHandler ("OnPlayerMarkerHit", thePlayer) function CommandMk local getPlayerMoney (thePlayer) end if getPlayerMoney (thePlayer) >= 1500 then outputChatBox ("You bought 25% of health !") end if not getPlayerMoney (thePlayer) then outputChatBox ("You do not have enough money !") end addCommandHandler ("mk",player) Serverside : function payMe takePlayerMoney ( 1500 , thePlayer) end addEventHandler ("OnPlayerCommand" ,thePlayer) function Heal getElementHealth (thePlayer) setElementHealth ( thePlayer, getElementHealth(thePlayer) +25 ) end Any help is welcomed. Link to comment
xXMADEXx Posted May 21, 2013 Share Posted May 21, 2013 Your getting functions & events wayy mixed up. From the looks of it, you are really new to scripting. Client: local theMarker = createMarker ( x, y, z, "cylinder", 3, 0 255 0 ) function onMarkerHit () outputChatBox ("Type /mk to buy 25% of Health") end addEventHandler ("onClientMarkerHit", onMarkerHit) function commandMK ( ) if ( getPlayerMoney ( localPlayer ) > 1499 ) then outputChatBox("You have bought 25% health for $1,500", 0, 255, 0) triggerServerEvent ( "setPlayerHealth", localPlayer ) end end addCommandHandler( "mk", commandMK ) Server: function setPlayerHealth ( ) local newHealth = getElementHealth ( source ) + 25 setElementHealth ( source, newHealth ) takPlayerMoney ( source, 1500 ) end addEvent ( "setPlayerHealth", true) addEventHandler ( "setPlayerHealth", root, setPlayerHealth) Link to comment
Sasu Posted May 21, 2013 Share Posted May 21, 2013 function medicKit local theMarker = createMarker ( x, y, z, "cylinder", 0 255 0 ) end addEventHandler("onResourceStart", resourceRoot, medicKit) function MarkerHit(hitElement) if source == theMarker and getElementType(hitElement) == "player" then outputChatBox ("Type /mk to buy 25% of Health", hitElement) end end addEventHandler ("onMarkerHit", root, MarkerHit) function CommandMk(thePlayer) local money = getPlayerMoney (thePlayer) if money >= 1500 then local health = getElementHealth(thePlayer) if health ~= 200 then takePlayerMoney(thePlayer, 1500) setElementHealth(thePlayer, health+25) outputChatBox ("You bought 25% of health !", thePlayer) end else outputChatBox ("You do not have enough money !", thePlayer) end addCommandHandler ("mk", CommandMk) Or you can do all in server side. Link to comment
RaceXtreme Posted May 21, 2013 Share Posted May 21, 2013 Lol, it really not going to work because you're messing up with Lua syntax! In order to make a script to heal players in your server, first heal yourself with this book: http://www.lua.org/pil/1.html After this, you can take a look in this script below: And you can use it only in the Client-Side: thePlayer = getLocalPlayer () addEventHandler ("OnResourceStart", getResourceRootElement(), function () theMarker = createMarker ( x, y, z, "cylinder", 0 255 0 ) end) addEventHandler ("OnPlayerMarkerHit", theMarker, function () outputChatBox ("Type /mk to buy 25% of Health") end) ddCommandHandler ( "mk", function () if isElementWithinMarker(thePlayer, theMarker) then local money = getPlayerMoney (thePlayer) local health = getElementHealth (thePlayer) if money >= 1500 and health ~= 200 then takePlayerMoney ( 1500 ) setElementHealth ( thePlayer, health + 25 ) outputChatBox ("You bought 25% of health !") else outputChatBox ("You do not have enough money !") end else outputChatBox ("You're not in the Marker !") end end) Link to comment
Blaawee Posted May 21, 2013 Share Posted May 21, 2013 I recommend to use it in server side. Link to comment
SkrillexX Posted May 21, 2013 Author Share Posted May 21, 2013 Thanks for helping me all, but sorry , i am new .. btw this forum is for experienced scripters only ? Link to comment
Mega9 Posted May 21, 2013 Share Posted May 21, 2013 This forum is actually to help new scripters like you. So no, anybody may ask for help here as long as the script is not stolen or leaked. Link to comment
xXMADEXx Posted May 21, 2013 Share Posted May 21, 2013 Lol, it really not going to work because you're messing up with Lua syntax! In order to make a script to heal players in your server, first heal yourself with this book: http://www.lua.org/pil/1.htmlAfter this, you can take a look in this script below: And you can use it only in the Client-Side: thePlayer = getLocalPlayer () addEventHandler ("OnResourceStart", getResourceRootElement(), function () theMarker = createMarker ( x, y, z, "cylinder", 0 255 0 ) end) addEventHandler ("OnPlayerMarkerHit", theMarker, function () outputChatBox ("Type /mk to buy 25% of Health") end) ddCommandHandler ( "mk", function () if isElementWithinMarker(thePlayer, theMarker) then local money = getPlayerMoney (thePlayer) local health = getElementHealth (thePlayer) if money >= 1500 and health ~= 200 then takePlayerMoney ( 1500 ) setElementHealth ( thePlayer, health + 25 ) outputChatBox ("You bought 25% of health !") else outputChatBox ("You do not have enough money !") end else outputChatBox ("You're not in the Marker !") end end) "ddCommandHandler ( "mk", function ()" Link to comment
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