IMariukas Posted April 6, 2013 Share 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 ) Link to comment
Castillo Posted April 6, 2013 Share Posted April 6, 2013 That script doesn't make any sense. Link to comment
IMariukas Posted April 6, 2013 Author Share 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. Link to comment
Castillo Posted April 6, 2013 Share Posted April 6, 2013 Well, what you did doesn't make any sense. You need the following functions: addCommandHandler getPlayerMoney takePlayerMoney giveWeapon outputChatBox Link to comment
IMariukas Posted April 6, 2013 Author Share Posted April 6, 2013 So what to write ??because i don't know what other to write with those "If" functions Link to comment
Max+ Posted April 6, 2013 Share 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 ) Link to comment
Castillo Posted April 6, 2013 Share Posted April 6, 2013 That's wrong Max, he should use addCommandHandler. Link to comment
Moderators IIYAMA Posted April 6, 2013 Moderators Share Posted April 6, 2013 https://wiki.multitheftauto.com/wiki/AddCommandHandler Link to comment
NodZen Posted April 6, 2013 Share Posted April 6, 2013 An example: addCommandHandler("giveM4", Give) Link to comment
iPrestege Posted April 6, 2013 Share 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 ) Link to comment
IMariukas Posted April 6, 2013 Author Share Posted April 6, 2013 Thank you Mr.Pres[T]ege Verry Much! Link to comment
tosfera Posted April 6, 2013 Share 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 Link to comment
iPrestege Posted April 6, 2013 Share Posted April 6, 2013 Thank you Mr.Pres[T]ege Verry Much! You're Welcome . @ test local not Local ! Link to comment
tosfera Posted April 6, 2013 Share Posted April 6, 2013 Thank you Mr.Pres[T]ege Verry Much! You're Welcome . @ test local not Local ! haha soz, typo. Link to comment
iPrestege Posted April 6, 2013 Share Posted April 6, 2013 Thank you Mr.Pres[T]ege Verry Much! You're Welcome . @ test local not Local ! haha soz, typo. No Problem . Link to comment
xXMADEXx Posted April 6, 2013 Share 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 ) Link to comment
iPrestege Posted April 6, 2013 Share 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? Link to comment
IMariukas Posted April 6, 2013 Author Share 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 Link to comment
iPrestege Posted April 6, 2013 Share 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 . Link to comment
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