IMariukas Posted April 6, 2013 Posted April 6, 2013 Can somoene explain what's the problem? local player = getLocalPlayer function buyweapon (player,command) takePlayerMoney ( player, 2000 ) if true then outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!", getRootElement(), 255, 255, 255, true ) giveWeapon ( player, 31, 200 ) end else if false then outputChatBox ( "#00FF00You Don't Have Enough Money!", getRootElement(), 255, 255, 255, true ) end addCommandHandler ( "buym4", buyweapon ) "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right! - http://www.lua.org/about.html
Castillo Posted April 6, 2013 Posted April 6, 2013 That script doesn't make any sense. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
IMariukas Posted April 6, 2013 Author Posted April 6, 2013 I wanted to make a simple test script where you write buym4 and if you have enough money it gives you weapon and writes on chat box and if you don't have enough money it only writes that you don't have enough money. "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right! - http://www.lua.org/about.html
Castillo Posted April 6, 2013 Posted April 6, 2013 Well, what you did doesn't make any sense. You need the following functions: addCommandHandler getPlayerMoney takePlayerMoney giveWeapon outputChatBox San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
IMariukas Posted April 6, 2013 Author Posted April 6, 2013 So what to write ??because i don't know what other to write with those "If" functions "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right! - http://www.lua.org/about.html
Max+ Posted April 6, 2013 Posted April 6, 2013 addEventHandler('onPlayerCommand', root, function (cmd) if (cmd == 'buym4' ) then if(getPlayerMoney(source) >=2000 ) then takePlayerMoney(source, 2000) giveWeapon(source, 31, 200 ) outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!", source, 255, 255, 0) else outputChatBox ( "#00FF00You Don't Have Enough Money!", source, 255, 255, 0) end end end ) - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
Castillo Posted April 6, 2013 Posted April 6, 2013 That's wrong Max, he should use addCommandHandler. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Max+ Posted April 6, 2013 Posted April 6, 2013 Why it's worng ? - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
Moderators IIYAMA Posted April 6, 2013 Moderators Posted April 6, 2013 https://wiki.multitheftauto.com/wiki/AddCommandHandler Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
NodZen Posted April 6, 2013 Posted April 6, 2013 An example: addCommandHandler("giveM4", Give) ------------------------------------------------------------------------------------------ My scripts http://community.multitheftauto.com/index.php?p=resources&s=details&id=6977 http://community.multitheftauto.com/index.php?p=resources&s=details&id=7740
iPrestege Posted April 6, 2013 Posted April 6, 2013 function buyweapon (player) if getPlayerMoney(player) >= 2000 then takePlayerMoney ( player, 2000 ) outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!",player, 255, 255, 255, true ) giveWeapon ( player, 31, 200 ) else outputChatBox ( "#00FF00You Don't Have Enough Money!",player, 255, 255, 255, true ) end end addCommandHandler ( "buym4", buyweapon )
IMariukas Posted April 6, 2013 Author Posted April 6, 2013 Thank you Mr.Pres[T]ege Verry Much! "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right! - http://www.lua.org/about.html
tosfera Posted April 6, 2013 Posted April 6, 2013 (edited) Thank you Mr.Pres[T]ege Verry Much! Have you learned something from it? Cause this is kinda... first day of programming that people are learning you that this wont work; if true then What has to be true, what is true? Whats going on? O_O A true/false is a returned bool value. So if you got a function that returns a boolean you can get 2 things back; True or False. So lets make a little script with it; local pedInVehicle = isPedInVehicle(source); if (pedInVehicle) then -- if its true outputChatBox("In a car!", source); else outputChatBox("FALSE!, aint in a car brotha!", source); end Get it? (aint trying to be a btch or so, just want people to learn from their mistakes cause of my mistakes, I gained alot of knowledge) Edited April 6, 2013 by Guest If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
iPrestege Posted April 6, 2013 Posted April 6, 2013 Thank you Mr.Pres[T]ege Verry Much! You're Welcome . @ test local not Local !
tosfera Posted April 6, 2013 Posted April 6, 2013 Thank you Mr.Pres[T]ege Verry Much! You're Welcome . @ test local not Local ! haha soz, typo. If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
iPrestege Posted April 6, 2013 Posted April 6, 2013 Thank you Mr.Pres[T]ege Verry Much! You're Welcome . @ test local not Local ! haha soz, typo. No Problem .
xXMADEXx Posted April 6, 2013 Posted April 6, 2013 Try this: local player = getLocalPlayer function buyweapon (player,command) if (getPlayerMoney(player) > 1999) then -- 1999 will acculy be 200 outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!", 255, 255, 255, true ) giveWeapon ( player, 31, 200 ) takePlayerMoney ( player, 2000 ) else outputChatBox ( "#00FF00You Don't Have Enough Money!", 255, 255, 255, true ) end end addCommandHandler ( "buym4", buyweapon ) The Ultimate Lua Tutorial! | MTA PHP SDK
iPrestege Posted April 6, 2013 Posted April 6, 2013 Try this: local player = getLocalPlayer function buyweapon (player,command) if (getPlayerMoney(player) > 1999) then -- 1999 will acculy be 200 outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!", 255, 255, 255, true ) giveWeapon ( player, 31, 200 ) takePlayerMoney ( player, 2000 ) else outputChatBox ( "#00FF00You Don't Have Enough Money!", 255, 255, 255, true ) end end addCommandHandler ( "buym4", buyweapon ) The problem solved in the first page but i have a question why you use localPlayer server side?
IMariukas Posted April 6, 2013 Author Posted April 6, 2013 Eh guys i don't need those if and then tutorials i already readed some in lua and tested on lua demo and then i tried on mta lua "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right! - http://www.lua.org/about.html
iPrestege Posted April 6, 2013 Posted April 6, 2013 Eh guys i don't need those if and then tutorials i already readed some in lua and tested on lua demo and then i tried on mta lua Good Try .
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