Jump to content

[Help] Stock system (forex)


STINGX

Recommended Posts

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 by STINGX
Link to post
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 post
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 post

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 by STINGX
Link to post
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 by STINGX
Link to post

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 post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...