1LoL1 Posted November 26, 2015 Share Posted November 26, 2015 Hello, i created script but how i can delete amount 1.x i want only 1-999999999 not 1.1 - 1.999999 Please can anyone help me? function www (source,command,amount) local money = getPlayerMoney(source) local amount = tonumber(amount) if (amount) then if tonumber(money) >= amount and amount > 0 then setElementData(test, "www", (getElementData(test, "www") or 0) + amount) takePlayerMoney(source, amount) outputChatBox("Player "..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "").." -->"..convertNumber(amount).."$!", getRootElement(), 255, 0, 0, true) else outputChatBox("...", source, 255, 0, 0, true) end end end addCommandHandler("ddr", www) Link to comment
Castillo Posted November 26, 2015 Share Posted November 26, 2015 You don't want decimals? if so, then use math.floor. Link to comment
1LoL1 Posted November 26, 2015 Author Share Posted November 26, 2015 You don't want decimals? if so, then use math.floor. Oh thanks. Works. Link to comment
1LoL1 Posted November 26, 2015 Author Share Posted November 26, 2015 I have window but how i can defined of server-side ped money to client-side -> window function ped () mmm = createPed(0, -2715.1787109375,1330.7080078125,7.1677074432373, 270) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), ped) What i must use here?: local money = getPlayerMoney(mmm) or what please help? Link to comment
1LoL1 Posted November 26, 2015 Author Share Posted November 26, 2015 What? I have client-side window and there i have local money = getPlayerMoney() guiSetText(label, ""..money.."") but how i can getPlayerMoney of serverside "Ped" Link to comment
Castillo Posted November 26, 2015 Share Posted November 26, 2015 Peds don't have money. Link to comment
1LoL1 Posted November 26, 2015 Author Share Posted November 26, 2015 Peds don't have money. sorry this i have: (getElementData(ped, "Money") or 0) Link to comment
Rockyz Posted November 27, 2015 Share Posted November 27, 2015 you canonnt give / take / get ped Money Link to comment
1LoL1 Posted November 27, 2015 Author Share Posted November 27, 2015 you canonnt give / take / get ped Money And can i give money to element? Link to comment
Rockyz Posted November 27, 2015 Share Posted November 27, 2015 you only can give to a player Link to comment
ALw7sH Posted November 27, 2015 Share Posted November 27, 2015 Actully you can, but you have to create your own money system using setElementData getElementData or whatever method you want to Here's an example function buySomthing(element) if getElementData(element) >= 500 then takeElementMoney(element,500) end end -------------- Our new money system function getElementMoney(element) if isElement(element) then return getElementData(element,"Money") or 0 end return false end function setElementMoney(element,money) if isElement(element) and type(money) == "number" then return setElementData(element,"Money",money) end return false end function takeElementMoney(element,money) if isElement(element) and type(money) == "number" then return setElementMoney(element,getElementMoney(element)-money)) end return false end function giveElementMoney(element,money) if isElement(element) and type(money) == "number" then return setElementMoney(element,getElementMoney(element)+money)) end return false end Link to comment
1LoL1 Posted November 27, 2015 Author Share Posted November 27, 2015 Actully you can, but you have to create your own money system using setElementData getElementData or whatever method you want to Here's an example function buySomthing(element) if getElementData(element) >= 500 then takeElementMoney(element,500) end end -------------- Our new money system function getElementMoney(element) if isElement(element) then return getElementData(element,"Money") or 0 end return false end function setElementMoney(element,money) if isElement(element) and type(money) == "number" then return setElementData(element,"Money",money) end return false end function takeElementMoney(element,money) if isElement(element) and type(money) == "number" then return setElementMoney(element,getElementMoney(element)-money)) end return false end function giveElementMoney(element,money) if isElement(element) and type(money) == "number" then return setElementMoney(element,getElementMoney(element)+money)) end return false end But this not work ERROR: ERROR: Bad argument #1 to "floor" (number expected, got nil) function www (source,element,command,amount) local money = getPlayerMoney(source) local amount = tonumber(math.floor(amount)) if amount then if tonumber(money) >= amount and amount > 0 then setElementData(element, "data", (getElementData(element, "data") or 0) + amount) takePlayerMoney(source, amount) outputChatBox("Player "..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "").." --> "..amount.."$", getRootElement(), 255, 0, 0, true) else outputChatBox("...", source, 255, 0, 0, true) end end end addCommandHandler("ww", www) Link to comment
Moderators IIYAMA Posted November 28, 2015 Moderators Share Posted November 28, 2015 Apply the math.floor function on the variable >amount<, after converting(tonumber) and the validation(if amount then). Which ends at line 4. Link to comment
1LoL1 Posted November 28, 2015 Author Share Posted November 28, 2015 Apply the math.floor function on the variable >amount<, after converting(tonumber) and the validation(if amount then).Which ends at line 4. What? Link to comment
Moderators IIYAMA Posted November 28, 2015 Moderators Share Posted November 28, 2015 Apply the math.floor function on line 5... instead of where it is now. Link to comment
ALw7sH Posted November 28, 2015 Share Posted November 28, 2015 delete "element" from line 1 then replace element with source in line 6 change line 3 to local amount = math.floor(tonumber(amount)) because amount is string and you can't use "math.floor" which work only with numbers before you convert amount to number Link to comment
Moderators IIYAMA Posted November 28, 2015 Moderators Share Posted November 28, 2015 When the tonumber function receive something else than number characters(as a string), it will return nil/false. Problem will remains the same when you type wrong characters. Link to comment
ALw7sH Posted November 28, 2015 Share Posted November 28, 2015 Here is a solution local amount = (type(tonumber(amount)) == "number") and math.floor(tonumber(amount)) Link to comment
1LoL1 Posted November 28, 2015 Author Share Posted November 28, 2015 delete "element" from line 1then replace element with source in line 6 change line 3 to local amount = math.floor(tonumber(amount)) because amount is string and you can't use "math.floor" which work only with numbers before you convert amount to number But i don't want to player i have firm system. Link to comment
1LoL1 Posted November 28, 2015 Author Share Posted November 28, 2015 what's firm? Company system. So i need takePlayerMoney from player and givePlayerMoney to company. Link to comment
Moderators IIYAMA Posted November 28, 2015 Moderators Share Posted November 28, 2015 what's firm? Company system. So i need takePlayerMoney from player and givePlayerMoney to company. That has at the moment nothing to do with this. You are using addCommandHandler and not the company resource to trigger this function. Link to comment
1LoL1 Posted November 28, 2015 Author Share Posted November 28, 2015 what's firm? Company system. So i need takePlayerMoney from player and givePlayerMoney to company. That has at the moment nothing to do with this. You are using addCommandHandler and not the company resource to trigger this function. What? i want to with addCommandHandler send $ to company.. 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