Jump to content

[HELP] Learning how to script


Recommended Posts

Sorry, but you seem to have no idea whatsoever, what you're doing there.

"if health > 1 then" makes no sense. Do you even understand the meaning of this line?

And setPlayerHealth does not exist. Would you have read the errors, it would have been clear to you.

Please start learning scripting, especially control structures.

Another thing: "if money > 100 then" also has a flaw. It should be ">=", because otherwise, people with exactly 100$ won't be able to use your pickup.

A hint to fix this: https://wiki.multitheftauto.com/wiki/SetElementHealth

Link to comment

okay i fixed the bugs, and now this one is the good one:

local root = getRootElement()
 
addEventHandler("onResourceStart", root,
function()
a = createPickup (-707, 973, 12, 0, 0, 0)
end
)
addEventHandler("onPickupUse", root, 
function( thePlayer ) 
if (source == a) then 
local health = getElementHealth(thePlayer) 
if (health >=5 and health <= 100) then    
local money = getPlayerMoney(thePlayer) 
if (money >= 100) then 
takePlayerMoney(thePlayer, 100) 
setElementHealth ( thePlayer, 100 ) 
outputChatBox("* A hot nurse gave you a nice healing process!", thePlayer)
else 
outputChatBox("* You dont have enough money!", thePlayer ) 
end 
else
outputChatBox("*You are healhty enough to be alife", thePlayer)
end 
end 
end 
)

Link to comment

this script will create always new pickup when eny script start.

use this to fix it:

local resroot = getResourceRootElement(getThisResource())
local root = getRootElement()
 
addEventHandler("onResourceStart", resroot,
function()
a = createPickup (-707, 973, 12, 0, 0, 0)
end
)
addEventHandler("onPickupUse", root, 
function( thePlayer ) 
if (source == a) then 
local health = getElementHealth(thePlayer) 
if (health >=5 and health <= 100) then    
local money = getPlayerMoney(thePlayer) 
if (money >= 100) then 
takePlayerMoney(thePlayer, 100) 
setElementHealth ( thePlayer, 100 ) 
outputChatBox("* A hot nurse gave you a nice healing process!", thePlayer)
else 
outputChatBox("* You dont have enough money!", thePlayer ) 
end 
else
outputChatBox("*You are healhty enough to be alife", thePlayer)
end 
end 
end 
)

Link to comment
this script will create always new pickup when eny script start.

use this to fix it:

local resroot = getResourceRootElement(getThisResource())
local root = getRootElement()
 
addEventHandler("onResourceStart", resroot,
function()
a = createPickup (-707, 973, 12, 0, 0, 0)
end
)
addEventHandler("onPickupUse", root, 
function( thePlayer ) 
if (source == a) then 
local health = getElementHealth(thePlayer) 
if (health >=5 and health <= 100) then    
local money = getPlayerMoney(thePlayer) 
if (money >= 100) then 
takePlayerMoney(thePlayer, 100) 
setElementHealth ( thePlayer, 100 ) 
outputChatBox("* A hot nurse gave you a nice healing process!", thePlayer)
else 
outputChatBox("* You dont have enough money!", thePlayer ) 
end 
else
outputChatBox("*You are healhty enough to be alife", thePlayer)
end 
end 
end 
)

it wont be needed, the time from the respawning of the pickup is: 0.

so it will never disapear :)

Link to comment
  • 1 year later...

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