Jump to content

[HELP] Medical kit


Recommended Posts

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

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

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

"ddCommandHandler ( "mk", function ()" xD

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