Jump to content

[HELP]Second currency in mta


Seba500PLK

Recommended Posts

Posted (edited)

Hello, whether it is possible to create a second currency to the server?, the second currency wants to use to buy vip If possible ask for any some code

Edited by Guest
Posted

I'm sure you can create your own system and use database functions. And then with exports functions you can easily save and get money. Maybe there is even an easier way.

Posted

I found some code, now help with this. He wants to list the screen but does not work. "Twoje PP" does not exist on the screen. Help

This is not the whole part of the code

  
--Client 
function getPlayerPoints (thePlayer) 
    if saveMethod == "accounts" then 
        if not isGuestAccount(getPlayerAccount(thePlayer)) then 
            local account = getPlayerAccount(thePlayer) 
            local points = getAccountData(account, "points_class") 
            return tonumber(points) 
        else 
            outputDebugString("pointsystem_classes - getPlayerPoints (Account is guest! Can't get points!)") 
        end 
    elseif saveMethod == "database" then 
        local serial = getPlayerSerial(thePlayer) 
        local points = executeSQLSelect ( "pointsystem_classes", "points","serial = '" .. serial .. "'") 
        if points then 
            return tonumber(points[1]["points"]) 
        else 
            outputDebugString("pointsystem_classes - getPlayerPoints (Database unknow problem! Can't get points!)") 
        end 
    end 
end 

  
--Server 
addEventHandler("onClientResourceStart", resourceRoot, 
    function()     
    end 
) 
addEventHandler("onClientRender", root, 
    function() 
    screenWidth, screenHeight = guiGetScreenSize() 
     
     
         
        local cash2 = getPlayerPoints( getLocalPlayer() ) 
        dxDrawText("Twoje PP: #FF0000"..cash2, screenWidth * 0.7 / 2, screenHeight * 0, screenWidth * 0.5 / 2, screenHeight * 0, tocolor(2, 2, 214, 255), 1, "bankgothic", "left", "top", false, false, true, true) 
         
         
        --dxDrawText(""..cash, screenWidth * 0.76 / 2, screenHeight * 0.003, screenWidth * 0.5 / 2, screenHeight * 0, tocolor(255, 0, 0, 255), 0.80, "bankgothic", "left", "top", false, false, true, false, false) 
    end 
) 

Posted

Stop flooding this topic.

Your code could just be something like this:

-- Server side Code 
function getPlayerMoney ( player )  
    local m = tonumber ( getElementData ( player, "p_money" ) )  
    if ( not m ) then 
        m = 0 
        setElementData ( player, "p_money", 0 ) 
    end 
  
    return m 
end  
  
function setPlayerMoney ( player, money ) 
    return setElementData ( player, "p_money", money ) 
end  
  
function givePlayerMoney ( player, money ) 
    local c = getPlayerMoney ( player ) 
    return setPlayerMoney ( player, c + money ) 
end 
  
  
  
  
  
-- Client side Code 
function getPlayerMoney ( )  
    local m = tonumber ( getElementData ( localPlayer, "p_money" ) )  
    if ( not m ) then 
        m = 0 
        setElementData ( localPlayer, "p_money", 0 ) 
    end 
  
    return m 
end  
  
function setPlayerMoney ( money ) 
    return setElementData ( localPlayer, "p_money", money ) 
end  
  
function givePlayerMoney ( money ) 
    local c = getPlayerMoney ( localPlayer ) 
    return setPlayerMoney ( localPlayer, c + money ) 
end 
  
local sx, sy = guiGetScreenSize ( ) 
addEventHandler ( "onClientRender", root, function ( ) 
    dxDrawText ( "You currently have $"..tostring ( getPlayerMoney ( ) ), 0, 0, sx, sy, tocolor ( 0, 255, 0, 255 ), 2, "default", "center", "top" ) 
end ) 

Posted
Stop flooding this topic.

Your code could just be something like this:

-- Server side Code 
function getPlayerMoney ( player )  
    local m = tonumber ( getElementData ( player, "p_money" ) )  
    if ( not m ) then 
        m = 0 
        setElementData ( player, "p_money", 0 ) 
    end 
  
    return m 
end  
  
function setPlayerMoney ( player, money ) 
    return setElementData ( player, "p_money", money ) 
end  
  
function givePlayerMoney ( player, money ) 
    local c = getPlayerMoney ( player ) 
    return setPlayerMoney ( player, c + money ) 
end 
  
  
  
  
  
-- Client side Code 
function getPlayerMoney ( )  
    local m = tonumber ( getElementData ( localPlayer, "p_money" ) )  
    if ( not m ) then 
        m = 0 
        setElementData ( localPlayer, "p_money", 0 ) 
    end 
  
    return m 
end  
  
function setPlayerMoney ( money ) 
    return setElementData ( localPlayer, "p_money", money ) 
end  
  
function givePlayerMoney ( money ) 
    local c = getPlayerMoney ( localPlayer ) 
    return setPlayerMoney ( localPlayer, c + money ) 
end 
  
local sx, sy = guiGetScreenSize ( ) 
addEventHandler ( "onClientRender", root, function ( ) 
    dxDrawText ( "You currently have $"..tostring ( getPlayerMoney ( ) ), 0, 0, sx, sy, tocolor ( 0, 255, 0, 255 ), 2, "default", "center", "top" ) 
end ) 

you forgot to add localPlayer inside the getPlayerMoney ( )

or just replace it with c

Posted

you forgot to add localPlayer inside the getPlayerMoney ( )

or just replace it with c

It doesn't need a player argument on the client side, it will only work for the local player.

Posted

you forgot to add localPlayer inside the getPlayerMoney ( )

or just replace it with c

It doesn't need a player argument on the client side, it will only work for the local player.

Oh Right i saw the server argument ,

Posted

Instead of 'set/getElementData' use 'set/getAccountData', so it saves. But the player has to be logged in by then. (This all is server-side.

Posted
  
--Server 
function getPlayerMoney ( player ) 
    local m = tonumber ( getAccountData ( player, "p_money" ) ) 
    if ( not m ) then 
        m = 0 
        setAccountData ( player, "p_money", 0 ) 
    end 
  
    return m 
end 
  
function setPlayerMoney ( player, money ) 
    return setAccountData ( player, "p_money", money ) 
end 
  
function givePlayerMoney ( player, money ) 
    local c = getPlayerMoney ( player ) 
    return setPlayerMoney ( player, c + money ) 
end 

dont work, no saved :(

Posted
  
--Server 
function getPlayerMoney ( player ) 
    local m = false 
    local gPlayerAccount = getPlayerAccount(player) 
    if (gPlayerAccount ~= false) and (isGuestAccount(gPlayerAccount) == false) then 
        m = tonumber ( getAccountData ( gPlayerAccount, "p_money" ) ) 
        if ( not m ) then 
            m = 0 
            setAccountData ( player, "p_money", 0 ) 
        end 
     end 
    return m 
end 

I did the first one, you can do the rest ;) (getPlayerAccount(player)) (If the player was not logged in, then it returns 'false')

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...