Need Help With my Lua Code
5 replies



07.03.11 02:41:17 am
addhook("say","rpmenu")
function rpmenu(player, text)
if(text == "!buyhealth")then
if(money > 10)then
msg("MIRACLES!")
end
end
end
How do I get it to check a players money, then say "MIRACLES!"
The miracles part is a place holder to add 10 health to player.
function rpmenu(player, text)
if(text == "!buyhealth")then
if(money > 10)then
msg("MIRACLES!")
end
end
end
How do I get it to check a players money, then say "MIRACLES!"
The miracles part is a place holder to add 10 health to player.
Admin/mod comment:
you need help with choosing a decent title...Code:
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
addhook("say","rpgmenu")
function rpmenu(player,text)
if(text=="!buyhealth")then
if(player(player,"money"))then
msg("MIRACLES!")
parse("sethealth "..player.." "..player(player,"health")+10)
parse("setmoney "..player.." "..player(player,"money")-10)
end
end
end
function rpmenu(player,text)
if(text=="!buyhealth")then
if(player(player,"money"))then
msg("MIRACLES!")
parse("sethealth "..player.." "..player(player,"health")+10)
parse("setmoney "..player.." "..player(player,"money")-10)
end
end
end
I guess you substracts 10 of money
Should I come back and make one last map for CS2D?
That won't work. You're naming a function parameter just like the global function "player", freaking bad, Lua will try to call the local variable instead which will cause an error to be printed in console.
Code:
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
function rpmenu(pl, txt)
if text == "!buyhealth" then
local money = player(pl,"money")
if money > 10 then
parse("setmoney "..pl.." "..money-10)
parse("sethealth "..pl.." "..player(pl,"health")+10)
msg("MIRACLES!")
end
end
end
if text == "!buyhealth" then
local money = player(pl,"money")
if money > 10 then
parse("setmoney "..pl.." "..money-10)
parse("sethealth "..pl.." "..player(pl,"health")+10)
msg("MIRACLES!")
end
end
end
Sry, I just modified his lua to fix it, that is why I used "player" as a function parameter, I usually use "id" for players
What I have learned: never use "player" as a function parameter
btw flacko, I can make complexs scripts, I just make lots of mistakes before the right code.
What I have learned: never use "player" as a function parameter
btw flacko, I can make complexs scripts, I just make lots of mistakes before the right code.
Should I come back and make one last map for CS2D?
Before anything,
I don't care at all.
In that case you haven't understood what I meant.
You must NEVER name ANY variable (not only parameters) like a global function/variable.
By global CS2D function I mean player, parse, msg, msg2, print, addhook, menu, timer, image, game, map, etc.
If you name any global variable like that, you will lose the original function and you won't be able to access it again.
And if you name a local variable (or parameter) like one of the default functions you won't be able to access it again neither in the current scope nor in any of the inner scopes.
However, you will be able to use the original values once you get out of scope in this case.
Unknown_Soldier has written:
btw flacko, I can make complexs scripts, I just make lots of mistakes before the right code.
I don't care at all.
Unknown_Soldier has written:
What I have learned: never use "player" as a function parameter
In that case you haven't understood what I meant.
Flacko has written:
You're naming a function parameter just like the global function "player", freaking bad
You must NEVER name ANY variable (not only parameters) like a global function/variable.
By global CS2D function I mean player, parse, msg, msg2, print, addhook, menu, timer, image, game, map, etc.
If you name any global variable like that, you will lose the original function and you won't be able to access it again.
And if you name a local variable (or parameter) like one of the default functions you won't be able to access it again neither in the current scope nor in any of the inner scopes.
However, you will be able to use the original values once you get out of scope in this case.



