• ULX Command returning "expected then near =" error
    5 replies, posted
Hey guys, So I've been doing some work on a ULX command for Garry's Mod (ofc). Pretty much the user inputs how much they wish to "bet" from their pool of points, and a math.random round is done to pull up a random number. If that number in ends in a multiple of 11 then their initial investment is multiplied by 10 and added back to their pool of points. I'm completely stuck; I've written the code but I have no idea why it isn't working. For reference: [CODE]function ulx.roll (calling_ply, points) calling_ply.points = calling_ply.points or 0 calling_ply.points = calling_ply.points - points calling_ply.victory = (points*10) function f(n) print(n % 100 % 11 == 0) end if f(ran) = true ulx.fancyLogAdmin( calling_ply, "#A rolled #ran! #calling_ply.victory", points ) calling_ply.points = calling_ply.points + calling_ply.victory else ulx.fancyLogAdmin( calling_ply, "#A rolled #ran", points ) end end local ran = (math.random(000001, 1000000)) print(ran) f(ran) local roll = ulx.command("Multi", "ulx roll", ulx.roll, "!roll") roll:defaultAccess(ULib.ACCESS_ALL) roll:addParam{ type=ULib.cmds.NumArg, default=1, hint="rolling", ULib.cmds.round} roll:help("Roll for a chance to win big!.")[/CODE] Does anyone have an idea? Completely hit a roadblock.
Change [CODE]if f(ran) = true[/CODE] To [CODE]if f(ran) == true then[/CODE] After an if you should always put a then and to check if a variable is equal to something you should use two equals instead of one [editline]13th December 2015[/editline] Also, you should never create a function inside another function
[lua]--always indent, notepad++ and sublime both have an autoindent under "edit" function ulx.roll (calling_ply, points) local p = calling_ply.PS2_Wallet.points --changed this to display ps2 points if p > points then return false end --with your current system people with less money than what they are betting could still particiapte, this line fixes that calling_ply:PS2_AddStandardPoints(-points, "FROM !ROLL") --calling_ply.points = calling_ply.points - points don't know what this line is doing, commented out local victory = (points*10) --reward? not clear local ran = (math.random(000001, 1000000)) -- this is fine local didYouWin = (ran % 100 % 11 == 0) --this is a boolean saying whether or not the cp won, doesn't need brackets but i put em there anyway if didYouWin then -- don't need "if x == true then", in lua you can do if x then, it means the same thing ulx.fancyLogAdmin( calling_ply, "#A rolled #s, they won #s points", ran, victory ) --fancylog is really confusing just ignore this calling_ply:PS2_AddStandardPoints(victory, "FROM !ROLL") else ulx.fancyLogAdmin( calling_ply, "#A rolled #s", ran ) end end local roll = ulx.command("Multi", "ulx roll", ulx.roll, "!roll") roll:defaultAccess(ULib.ACCESS_ALL) roll:addParam{ type=ULib.cmds.NumArg, default=1, hint="amount to bet", ULib.cmds.round} roll:help("Roll for a chance to win big!.")[/lua] EDIT: he was using this for pointshop 2 btw, which is why i added those ps2 functions
[QUOTE=Splerge;49307208][lua]--always indent, notepad++ and sublime both have an autoindent under "edit" function ulx.roll (calling_ply, points) local p = calling_ply.PS2_Wallet.points --changed this to display ps2 points if p > points then return false end --with your current system people with less money than what they are betting could still particiapte, this line fixes that calling_ply:PS2_AddStandardPoints(-points, "FROM !ROLL") --calling_ply.points = calling_ply.points - points don't know what this line is doing, commented out local victory = (points*10) --reward? not clear local ran = (math.random(000001, 1000000)) -- this is fine local didYouWin = (ran % 100 % 11 == 0) --this is a boolean saying whether or not the cp won, doesn't need brackets but i put em there anyway if didYouWin then -- don't need "if x == true then", in lua you can do if x then, it means the same thing ulx.fancyLogAdmin( calling_ply, "#A rolled #s, they won #s points", ran, victory ) --fancylog is really confusing just ignore this calling_ply:PS2_AddStandardPoints(victory, "FROM !ROLL") else ulx.fancyLogAdmin( calling_ply, "#A rolled #s", ran ) end end local roll = ulx.command("Multi", "ulx roll", ulx.roll, "!roll") roll:defaultAccess(ULib.ACCESS_ALL) roll:addParam{ type=ULib.cmds.NumArg, default=1, hint="amount to bet", ULib.cmds.round} roll:help("Roll for a chance to win big!.")[/lua] EDIT: he was using this for pointshop 2 btw, which is why i added those ps2 functions[/QUOTE] I'm new to lua and i've tried to make a pointshop (original with a skin) version of this but have had trouble not sure why this is my code: [CODE][lua]function ulx.roll (calling_ply, points) local p = calling_ply:PS_GetPoints() --changed this to display points if p > points then return false end --with your current system people with less money than what they are betting could still particiapte, this line fixes that calling_ply:PS_TakePoints(points) --calling_ply.points = calling_ply.points - points don't know what this line is doing, commented out local victory = (points*2) --reward? not clear local ran = (math.random(000001, 1000000)) -- this is fine local didYouWin = (ran % 100 % 11 == 0) --this is a boolean saying whether or not the cp won, doesn't need brackets but i put em there anyway if didYouWin then -- don't need "if x == true then", in lua you can do if x then, it means the same thing ulx.fancyLogAdmin( calling_ply, "#A rolled #s, they won #s points", ran, victory ) --fancylog is really confusing just ignore this calling_ply:PS_GivePoints(victory) else ulx.fancyLogAdmin( calling_ply, "#A rolled #s", ran ) end end local roll = ulx.command("Betting", "ulx roll", ulx.roll, "!roll") roll:defaultAccess(ULib.ACCESS_ALL) roll:addParam{ type=ULib.cmds.NumArg, min=500, max=1000000, default=500, hint="amount to bet", ULib.cmds.round} roll:help("Roll for a chance to win big!.")[/lua][/CODE] sorry for any errors was in a rush.
[QUOTE=Kaibirdz;49744251]I'm new to lua and i've tried to make a pointshop (original with a skin) version of this but have had trouble not sure why this is my code: [CODE][lua]function ulx.roll (calling_ply, points) local p = calling_ply:PS_GetPoints() --changed this to display points if p > points then return false end --with your current system people with less money than what they are betting could still particiapte, this line fixes that calling_ply:PS_TakePoints(points) --calling_ply.points = calling_ply.points - points don't know what this line is doing, commented out local victory = (points*2) --reward? not clear local ran = (math.random(000001, 1000000)) -- this is fine local didYouWin = (ran % 100 % 11 == 0) --this is a boolean saying whether or not the cp won, doesn't need brackets but i put em there anyway if didYouWin then -- don't need "if x == true then", in lua you can do if x then, it means the same thing ulx.fancyLogAdmin( calling_ply, "#A rolled #s, they won #s points", ran, victory ) --fancylog is really confusing just ignore this calling_ply:PS_GivePoints(victory) else ulx.fancyLogAdmin( calling_ply, "#A rolled #s", ran ) end end local roll = ulx.command("Betting", "ulx roll", ulx.roll, "!roll") roll:defaultAccess(ULib.ACCESS_ALL) roll:addParam{ type=ULib.cmds.NumArg, min=500, max=1000000, default=500, hint="amount to bet", ULib.cmds.round} roll:help("Roll for a chance to win big!.")[/lua][/CODE] sorry for any errors was in a rush.[/QUOTE] so whats the problem that occurs? also remove the html from the code tags
[QUOTE=Splerge;49744294]so whats the problem that occurs? also remove the html from the code tags[/QUOTE] the problem is nothing, no points are taken, no points are given, nothing in chat happens and no errors in the logs [editline]15th February 2016[/editline] Also Splerge, on poseidon deathrun how did you get Kmapvote to work i've tried for ages but could not find any solution, [editline]15th February 2016[/editline] Never mind i fixed the betting but it only works sometimes
Sorry, you need to Log In to post a reply to this thread.