Jump to content

[HELP] Learning how to script


Recommended Posts

function onStart ()
marker = createMarker ( 0, 0, 0, "cylinder", 2.5, 0, 0, 255, 150 )
end
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource())           
 
function entering ( source )
local money = getPlayerMoney( source )
if ( money >= 100 ) then
setElementHealth ( source, 100 )
outputChatBox ( "Healthed", source, 0, 255, 0 )
else
outputChatBox ( "You dont have enoguht money! ( 100$ )", source, 255, 0, 0 )
end
end
addEventHandler ( "onMarkerHit", marker, entering )

no tested..

Link to comment

yeah but you do need to make an option too, when your health is 100%

he will still lose his cash right?:P

you should make an another option like:

a = getElementHealth (source)

if a == <100 then

or something like that xD

still nice done :)

Link to comment

Your code will not work TheRealCow... For couple of reasons:

- addEventHandler ( "onMarkerHit", marker, entering ) will be executed before the actual marker is created.

- DO NOT ever add source as function parameter.. You will get into issues that you wouldn't want if that function gets longer and other features are added to the function. This is not actually a reason why it won't work but an advice for you.

Also, if you expect player to be the element that hit the marker, make sure the element is player because getPlayerMoney will give warning if the element that hit the marker is vehicle (or player is inside vehicle). This should still work but if you release your resource always make sure it doesn't output any error/warning message because it's annoying if someone debugs his script and sees warning/error messages coming up from different resource.

And as m4sje said, you need to add an if statement to check if player's health is not full because you don't want to be charged $100 for nothing.

Link to comment

Sort of. You don't check and take player money. You don't need triggerServerEvent... what is it for? I suggest you look into other scripts or get to know MTA scripting more by reading wiki.

Link to comment
So.. Something like this?
function ghealth( thePlayer )
local health = getPlayerHealth(thePlayer)
if (health > 1) then	
    setPlayerHealth ( 100 )
triggerServerEvent ( "givehealth", getLocalPlayer(), "24","10" )
else
outputChatBox("* You dont have enough money!", thePlayer )
end
end

you can try this:

local root = getRootElement()
addEventHandler("onPickupUse", root,
function( thePlayer )
local health = getPlayerHealth(thePlayer)
if (health > 1) then	
local money = getPlayerMoney(thePlayer)
if (money > 100) then
takePlayerMoney(thePlayer, 100)
    setPlayerHealth ( 100 )
else
outputChatBox("* You dont have enough money!", thePlayer )
end
end
end
)

Link to comment

Aaahh I think you should add this to it:

if (source == name-from-pickup) then

Add that after the function (thePlayer)

And add a new "end";)

Bec he cant know where he have to add the function bec you didn't gave a pickup where it happens ;)

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