Turbe$Z Posted March 9, 2017 Posted March 9, 2017 function payScript(player,cmd,other,amount) local money = getPlayerMoney(player) local otherPlayer = getPlayerFromName(other) if not other or not amount then outputChatBox("#00BAFF[Play] #FFffFFHelyes használat: #0088FF/pay <név> <összeg>!",player,0,255,255, true) end if ((money - amount) < 0) then outputChatBox("#00BAFF[Play] #FFffFFNincs elegendő #0088FFpénzed!",player,0,255,255, true) return else setPlayerMoney(otherPlayer,getPlayerMoney(otherPlayer) + amount) setPlayerMoney(player,money - amount) outputChatBox("#00bAFF[Play] #0088FF"..amount.."Ft-ot #FFffFFküldtél neki: #0088FF"..other.."!",player,0,255,255, true) outputChatBox("#00BAFF[Play] #FFffFFKaptál #0088FF"..amount.."Ft-ot #FFffFFtőle: #0088FF"..getPlayerName(player).."!",otherPlayer,0,255,255,true) end end addCommandHandler("pay",payScript) and i got this error: xy.lua:11: attempt to perform arithmetic on a boolean value how to fix this? My Fun server: My DD server:
LoPollo Posted March 9, 2017 Posted March 9, 2017 other is not a valid player name, so local otherPlayer = getPlayerFromName(other) is false, so getPlayerMoney(otherPlayer) + amount is getPlayerMoney(false) + amount, which should also throw a warning. Just checked really fast, so i'm sorry if i said something wrong.
Turbe$Z Posted March 9, 2017 Author Posted March 9, 2017 7 minutes ago, LoPollo said: other is not a valid player name, so local otherPlayer = getPlayerFromName(other) is false, so getPlayerMoney(otherPlayer) + amount is getPlayerMoney(false) + amount, which should also throw a warning. Just checked really fast, so i'm sorry if i said something wrong. how to fix this? My Fun server: My DD server:
3aGl3 Posted March 9, 2017 Posted March 9, 2017 You probably want to check the input before doing anything, so move the if from line 4 up to line 2. Then in line 4 you should check if otherPlayer is not false...so something like this. function payScript(player,cmd,other,amount) if not other or not amount then outputChatBox( "#00BAFF[Play] #FFffFFHelyes használat: #0088FF/pay <név> <összeg>!", player, 0, 255, 255, true ) else local money = getPlayerMoney(player) local otherPlayer = getPlayerFromName(other) if otherPlayer then if (money - amount) < 0 then outputChatBox("#00BAFF[Play] #FFffFFNincs elegendo #0088FFpénzed!",player,0,255,255, true) else setPlayerMoney( otherPlayer, getPlayerMoney(otherPlayer) + amount ) outputChatBox( "#00BAFF[Play] #FFffFFKaptál #0088FF"..amount.."Ft-ot #FFffFFtole: #0088FF".. getPlayerName(player).."!",otherPlayer,0,255,255,true ) setPlayerMoney( player, money - amount ) outputChatBox( "#00bAFF[Play] #0088FF"..amount.."Ft-ot #FFffFFküldtél neki: #0088FF"..other.."!",player,0,255,255, true ) end else outputChatBox( "Could not find player ".. other, player, 0, 255, 255, true ) end end end addCommandHandler( "pay", payScript ) 1
Turbe$Z Posted March 9, 2017 Author Posted March 9, 2017 38 minutes ago, 3aGl3 said: You probably want to check the input before doing anything, so move the if from line 4 up to line 2. Then in line 4 you should check if otherPlayer is not false...so something like this. function payScript(player,cmd,other,amount) if not other or not amount then outputChatBox( "#00BAFF[Play] #FFffFFHelyes használat: #0088FF/pay <név> <összeg>!", player, 0, 255, 255, true ) else local money = getPlayerMoney(player) local otherPlayer = getPlayerFromName(other) if otherPlayer then if (money - amount) < 0 then outputChatBox("#00BAFF[Play] #FFffFFNincs elegendo #0088FFpénzed!",player,0,255,255, true) else setPlayerMoney( otherPlayer, getPlayerMoney(otherPlayer) + amount ) outputChatBox( "#00BAFF[Play] #FFffFFKaptál #0088FF"..amount.."Ft-ot #FFffFFtole: #0088FF".. getPlayerName(player).."!",otherPlayer,0,255,255,true ) setPlayerMoney( player, money - amount ) outputChatBox( "#00bAFF[Play] #0088FF"..amount.."Ft-ot #FFffFFküldtél neki: #0088FF"..other.."!",player,0,255,255, true ) end else outputChatBox( "Could not find player ".. other, player, 0, 255, 255, true ) end end end addCommandHandler( "pay", payScript ) Thanks :DDD But players why can give minus value? My Fun server: My DD server:
3aGl3 Posted March 9, 2017 Posted March 9, 2017 Because there is no check for that, just add a amount > 0 to the first if.
Turbe$Z Posted March 9, 2017 Author Posted March 9, 2017 5 minutes ago, 3aGl3 said: Because there is no check for that, just add a amount > 0 to the first if. i added to first if, and i get this error: attempt to compare number with string My Fun server: My DD server:
Ayush Rathore Posted March 10, 2017 Posted March 10, 2017 (edited) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end function payScript(player,cmd,other,amount) if not other or not amount then outputChatBox( "#00BAFF[Play] #FFffFFHelyes használat: #0088FF/pay <név> <összeg>!", player, 0, 255, 255, true ) else if tonumber(amount) < 0 then outputChatBox( "amount is in negative", player, 0, 255, 255, true ) return end local money = getPlayerMoney(getPlayerFromPartialName(other)) local otherPlayer = getPlayerFromPartialName(other) if otherPlayer and otherPlayer ~= player then if (money - amount) < 0 then outputChatBox("#00BAFF[Play] #FFffFFNincs elegendo #0088FFpénzed!",player,0,255,255, true) else setPlayerMoney( otherPlayer, getPlayerMoney(otherPlayer) + amount ) outputChatBox( "#00BAFF[Play] #FFffFFKaptál #0088FF"..amount.."Ft-ot #FFffFFtole: #0088FF".. getPlayerName(player).."!",otherPlayer,0,255,255,true ) setPlayerMoney( player, money - amount ) outputChatBox( "#00bAFF[Play] #0088FF"..amount.."Ft-ot #FFffFFküldtél neki: #0088FF"..getPlayerName(otherPlayer).."!",player,0,255,255, true ) end else outputChatBox( "Could not find player ".. other, player, 0, 255, 255, true ) end end end addCommandHandler( "pay", payScript ) use this and change this line to your need outputChatBox( "amount is in negative", player, 0, 255, 255, true ) Edited March 10, 2017 by Ayush Rathore 1 I am a paid scripter. Contact: [email protected] Instagram: https://www.instagram.com/ayush_kumar_rathore/ Give me a 'Thanks' if I helped.
Turbe$Z Posted March 10, 2017 Author Posted March 10, 2017 3 hours ago, Ayush Rathore said: function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end function payScript(player,cmd,other,amount) if not other or not amount then outputChatBox( "#00BAFF[Play] #FFffFFHelyes használat: #0088FF/pay <név> <összeg>!", player, 0, 255, 255, true ) else if tonumber(amount) < 0 then outputChatBox( "amount is in negative", player, 0, 255, 255, true ) return end local money = getPlayerMoney(getPlayerFromPartialName(other)) local otherPlayer = getPlayerFromPartialName(other) if otherPlayer and otherPlayer ~= player then if (money - amount) < 0 then outputChatBox("#00BAFF[Play] #FFffFFNincs elegendo #0088FFpénzed!",player,0,255,255, true) else setPlayerMoney( otherPlayer, getPlayerMoney(otherPlayer) + amount ) outputChatBox( "#00BAFF[Play] #FFffFFKaptál #0088FF"..amount.."Ft-ot #FFffFFtole: #0088FF".. getPlayerName(player).."!",otherPlayer,0,255,255,true ) setPlayerMoney( player, money - amount ) outputChatBox( "#00bAFF[Play] #0088FF"..amount.."Ft-ot #FFffFFküldtél neki: #0088FF"..getPlayerName(otherPlayer).."!",player,0,255,255, true ) end else outputChatBox( "Could not find player ".. other, player, 0, 255, 255, true ) end end end addCommandHandler( "pay", payScript ) use this and change this line to your need outputChatBox( "amount is in negative", player, 0, 255, 255, true ) working the minus value, but now the script, when i type for example (i have 99.999.999$) and i type /pay xyplayer 1 , everyone money has going to 64k$, then i type again, and the my money +1, and doesn't send the money to the other player. how to fix this bug? (sorry for my bad English:() My Fun server: My DD server:
Ayush Rathore Posted March 11, 2017 Posted March 11, 2017 Try this function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end else return false end end function payScript(player,cmd,other,amount) local name = getPlayerFromPartialName(name) local atg local rpm = getPlayerMoney(player) local err = {} if not (name and isElement(name)) then err[1] = "Name not specified correctly." end if tonumber(amount) < 0 then err[2] = "Amount can't be negative." end atg = tonumber(amount) if (rpm-atg) < 0 then err[2] = "Given amount is more than yours." end if #err == 0 then setPlayerMoney(name,atg) outputChatBox("Given:"..atg.." to:"..getPlayerName(name),player,0,255,0) setPlayerMoney(player,(rpm-atg)) outputChatBox("Left:"..(rpm-atg).." to you.",player,0,255,0) else for i=1,#err do outputChatBox(err[1],player,0,255,0) end end end addCommandHandler( "pay", payScript ) 2 I am a paid scripter. Contact: [email protected] Instagram: https://www.instagram.com/ayush_kumar_rathore/ Give me a 'Thanks' if I helped.
Ayush Rathore Posted March 11, 2017 Posted March 11, 2017 (edited) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end else return false end end function payScript(player,cmd,other,amount) local name = getPlayerFromPartialName(name) local atg local rpm = getPlayerMoney(player) local err = {} if not (name and isElement(name)) then err[#err+1] = "Name not specified correctly." end if tonumber(amount) < 0 then err[#err+1] = "Amount can't be negative." end atg = tonumber(amount) if (rpm-atg) < 0 then err[#err+1] = "Given amount is more than yours." end if #err == 0 then setPlayerMoney(name,atg) outputChatBox("Given:"..atg.." to:"..getPlayerName(name),player,0,255,0) setPlayerMoney(player,(rpm-atg)) outputChatBox("Left:"..(rpm-atg).." to you.",player,0,255,0) else for i=1,#err do outputChatBox(err[i],player,0,255,0) end end end addCommandHandler( "pay", payScript ) If any one has copied it please update it with this Edited March 11, 2017 by Ayush Rathore contains some error 1 I am a paid scripter. Contact: [email protected] Instagram: https://www.instagram.com/ayush_kumar_rathore/ Give me a 'Thanks' if I helped.
Turbe$Z Posted March 11, 2017 Author Posted March 11, 2017 29 minutes ago, Ayush Rathore said: function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end else return false endendfunction payScript(player,cmd,other,amount) local name = getPlayerFromPartialName(name) local atg local rpm = getPlayerMoney(player) local err = {} if not (name and isElement(name)) then err[#err+1] = "Name not specified correctly." end if tonumber(amount) < 0 then err[#err+1] = "Amount can't be negative." end atg = tonumber(amount) if (rpm-atg) < 0 then err[#err+1] = "Given amount is more than yours." end if #err == 0 then setPlayerMoney(name,atg) outputChatBox("Given:"..atg.." to:"..getPlayerName(name),player,0,255,0) setPlayerMoney(player,(rpm-atg)) outputChatBox("Left:"..(rpm-atg).." to you.",player,0,255,0) else for i=1,#err do outputChatBox(err[i],player,0,255,0) end end endaddCommandHandler( "pay", payScript ) If any one has copied it please update it with this doesn't working i type a online player's name, but the script says "Name not specified correctly" My Fun server: My DD server:
Ayush Rathore Posted March 11, 2017 Posted March 11, 2017 wait i will correct it ang give it to you function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end else return false end end function payScript(player,cmd,other,amount) local name = getPlayerFromPartialName(other) local atg local rpm = getPlayerMoney(player) local err = {} if name == false then err[#err+1] = "Name not specified correctly." end if tonumber(amount) < 0 then err[#err+1] = "Amount can't be negative." end atg = tonumber(amount) if (rpm-atg) < 0 then err[#err+1] = "Given amount is more than yours." end if(player == name) then err[#err+1] = "You can't give it to yourself." end if #err == 0 then setPlayerMoney(name,atg) outputChatBox("Given:"..atg.." to:"..getPlayerName(name),player,0,255,0) setPlayerMoney(player,(rpm-atg)) outputChatBox("Left:"..(rpm-atg).." to you.",player,0,255,0) else for i=1,#err do outputChatBox(err[i],player,0,255,0) end end end addCommandHandler( "pay", payScript ) Try this 1 I am a paid scripter. Contact: [email protected] Instagram: https://www.instagram.com/ayush_kumar_rathore/ Give me a 'Thanks' if I helped.
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