STINGX Posted November 22, 2020 Share Posted November 22, 2020 (edited) Hello guys , I started working on the stocks system, but I have some problems. I want when the stock is positive ( green ), he gives him money, and when the stock is negative ( red ), he takes money from the player, that is, he buys a stock, and if he loses he loses money , like forex Thanks , --- Gridlist Value Test ---- for i,d in pairs(data) do local r = dgsGridListAddRow(GUIEditor.gridlist[1]) dgsGridListSetItemText(GUIEditor.gridlist[1], r, 1, d.name, false, false ) dgsGridListSetItemText(GUIEditor.gridlist[1], r, 2, "$ "..round(d.pps,2)*totalMidifier, false, false ) dgsGridListSetItemText(GUIEditor.gridlist[1], r, 3, (d.diff[1] and "▲ " or "▼ " )..round(d.diff[2],2).."%", false, false ) dgsGridListSetItemColor(GUIEditor.gridlist[1], r, 3, d.diff[1] and 0 or 255, d.diff[1] and 255 or 0, 0 ) triggerServerEvent("test",localPlayer,round(d.diff[2],2)) end for k,s in pairs(playerData) do local r = dgsGridListAddRow(GUIEditor.gridlist[2]) dgsGridListSetItemText( GUIEditor.gridlist[2],r, 1, k, false, false ) dgsGridListSetItemText( GUIEditor.gridlist[2],r, 2, s[1], false, false ) local old = s[2]*s[1] local new = getCompPPS( k )*s[1] local change = new-old >= 0 and true dgsGridListSetItemText(GUIEditor.gridlist[2], r, 3, "$"..round(new-old,2), false, false ) --dgsGridListSetItemText(GUIEditor.gridlist[2], r, 3, (d.diff[1] and "▲ " or "▼ " )..round(d.diff[2],2).."%", false, false ) dgsGridListSetItemColor( GUIEditor.gridlist[2],r, 3, change and 0 or 255, change and 255 or 0, 0 ) ----- client ----- local c = currentData[selectedBuyRow+1].name local n = currentData[selectedBuyRow+1].pps*totalMidifier if exports.global:getMoney(localPlayer ) - n >= 0 then triggerServerEvent( "onClientStockTransaction", localPlayer, n ) local temp = localPlayer:getData "Stocks" or {} for k,d in pairs(currentData) do if d.name == c then temp[d.name] = {temp[d.name] and temp[d.name][1]+totalMidifier or totalMidifier,currentData[selectedBuyRow+1].pps} end end localPlayer:setData("Stocks",temp,false) buyD = true saveStocks( ) -- triggerServerEvent( "onClientStockTransaction", localPlayer, -n ) else outputChatBox( "test") end ----- Server ----- function round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end addEvent( "TriggerMoneyTest", true ) addEventHandler( "TriggerMoneyTest", root, function( money,n ) local take = exports.global:getMoney(source, tonumber(money)-n) triggerClientEvent( source, "onConfirmPayment", source ) if decimals >= 0 then exports.global:takeMoney( source, tonumber(take)-n ) else -- decimals === exports.global:giveMoney( source, tonumber(take)+n ) end end) Edited November 22, 2020 by STINGX Link to comment
STINGX Posted November 22, 2020 Author Share Posted November 22, 2020 Help please ? , Link to comment
STINGX Posted November 22, 2020 Author Share Posted November 22, 2020 50 minutes ago, Tekken said: What is the problem ? I need if value in gridlist change to green give player money with this value or lose his money with this value if it red Like forex , I want to know check value with decimals Link to comment
Tekken Posted November 22, 2020 Share Posted November 22, 2020 So you want us to do that for you? Or have you tried and failed ? If so tell us where the problem is. Link to comment
STINGX Posted November 23, 2020 Author Share Posted November 23, 2020 15 hours ago, Tekken said: So you want us to do that for you? Or have you tried and failed ? If so tell us where the problem is. I already tried but I failed , I need to take player money or give with value in gridlist Link to comment
Tekken Posted November 23, 2020 Share Posted November 23, 2020 Show the part of code where you tried As I can’t really understand your code Link to comment
STINGX Posted November 23, 2020 Author Share Posted November 23, 2020 (edited) This code by timer increase or decrease okay? I don't now how to give player money or take money by this value --- This is trigger Client triggerServerEvent( "onClientStockTransaction", localPlayer, n ) ------------------------------- addEvent( "onClientStockTransaction", true ) addEventHandler( "onClientStockTransaction", root, function( money,n ) local take = exports.global:getMoney(source, tonumber(money)-n) triggerClientEvent( source, "onConfirmPayment", source ) if decimals >= 0 then exports.global:takeMoney( source, tonumber(take)-n ) else -- decimals === exports.global:giveMoney( source, tonumber(take)+n ) end end) I tried to give money or lose money but failed Edited November 23, 2020 by STINGX Link to comment
Tekken Posted November 23, 2020 Share Posted November 23, 2020 I don’t see where decimals variable was set, you have what error? /debugscript 3 Link to comment
STINGX Posted November 23, 2020 Author Share Posted November 23, 2020 (edited) 6 hours ago, Tekken said: I don’t see where decimals variable was set, you have what error? /debugscript 3 I don't have error , I failed to create this part of code only cause I don't know how to check decimals decrease or increase to give or take money from player , I added this code in client and server function round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end 3 minutes ago, STINGX said: I don't have error , I failed to create this part of code only cause I don't know how to check decimals decrease or increase to give or take money from player , I added this code in client and server function round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end and this is trigger using this function in gridlist , triggerServerEvent("test",localPlayer,round(d.diff[2],2)) Edited November 23, 2020 by STINGX Link to comment
Tekken Posted November 24, 2020 Share Posted November 24, 2020 Decimal is a number so all you have to do is If NewDecimal > oldDecimal then —give money elseif newDecimal < oldDecimal then —take money else — do nothing if decimal do not change end keep in mind this is very low level you will have to adjust to work with your code. Link to comment
corbinrozmus Posted March 29, 2022 Share Posted March 29, 2022 Please tell me if there are any improvements in your code because I am also working on a similar project now. I want to make something like the forex market trading website, as I really like this site and in general, I used it myself and was very satisfied. I don't know to program very well yet, but I have already implemented some projects. So I will be glad if you write to me and we can talk about your code. P.s I won't steal your code, but look at another way to solve a common problem Link to comment
AsiaCannon Posted July 12, 2022 Share Posted July 12, 2022 A very interesting and useful article; it will be very useful for people who are just starting to deal with crypto or bitcoin. I learned what cryptocurrency is a couple of years ago. My colleague at work told me that he found good forex indicators. I also decided to try it and was very pleased. Just now, AsiaCannon said: A very interesting and useful article; it will be very useful for people who are just starting to deal with crypto or bitcoin. I learned what cryptocurrency is a couple of years ago. My colleague at work told me that he found good forex indicators. I also decided to try it and was very pleased. Firstly, in a couple of years, the cryptocurrency has grown in price very much, and secondly, I like the security of money in cryptocurrency. So if someone has doubts, I recommend you read this article again and invest your money as soon as possible. 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