Jump to content

[HELP]Second currency in mta


Seba500PLK

Recommended Posts

did not work

  
--Server 
function onLogin( player) 
    if not getAccountData(player, "p_money") or getAccountData(player, "p_money") == nil then 
        setAccountData(player, "p_money", 0) 
    end 
end 
addEventHandler("onPlayerLogin", root, onLogin) 
  
  
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 

Link to comment

You didn't look what I did.

local gPlayerAccount = getPlayerAccount(player) 
    if (gPlayerAccount ~= false) and (isGuestAccount(gPlayerAccount) == false) then 

First get the player's account and check or he is logged in, if so, if not on Guest account, then continue.

Link to comment

...

function onLogin(previousAccount, currentAccount) 
    if not getAccountData(currentAccount, "p_money") or not getAccountData(currentAccount, "p_money") == nil then 
        setAccountData(currentAccount, "p_money", 0) 
    end 
end 
addEventHandler("onPlayerLogin", root, onLogin) 

Even though you have your answer now, I still want you to answer this question: Do you even use debugscript 3?

Link to comment

do not know too much on the triggers. please could you help? I'm sorry that so much of the time it takes

  
--Client 
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 screenWidth, screenHeight = guiGetScreenSize() 
addEventHandler ( "onClientRender", root, function ( ) 
     
    dxDrawText ( "Twoje PP: "..tostring ( getPlayerMoney ( ) ), screenWidth * 0.509 / 2, screenHeight * 0.022, screenWidth * 0.5 / 2, screenHeight * 0, tocolor ( 0, 0, 0, 255), 1, "bankgothic", "left", "top", false, false, true, true) 
    dxDrawText ( "#FFC000Twoje PP: #FF4000"..tostring ( getPlayerMoney ( ) ), screenWidth * 0.506 / 2, screenHeight * 0.02, screenWidth * 0.5 / 2, screenHeight * 0, tocolor ( 2, 2, 214, 255), 1, "bankgothic", "left", "top", false, false, true, true) 
end ) 

  
--Server 
function onLogin(previousAccount, currentAccount) 
    if not getAccountData(currentAccount, "p_money") or not getAccountData(currentAccount, "p_money") == nil then 
        setAccountData(currentAccount, "p_money", 0) 
    end 
end 
addEventHandler("onPlayerLogin", root, onLogin) 
  
  
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 
  
  
function getpoints ( player, command) 
local gPlayerAccount = getPlayerAccount(player) 
    outputChatBox(tostring(getAccountData ( gPlayerAccount, "p_money" ))) 
end 
addCommandHandler ( "getp", getpoints ) 

Link to comment
local gCurrentMoney = 0 
  
function receiveMoney(gMoney) 
    gCurrentMoney = gMoney 
end 
  
addEvent("onSendMoneyToClient", true) 
addEventHandler("onSendMoneyToClient", getRootElement(), receiveMoney) 
  
  
--Client 
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 screenWidth, screenHeight = guiGetScreenSize() 
addEventHandler ( "onClientRender", root, function ( ) 
    
    dxDrawText ( "Twoje PP: "..tostring ( getPlayerMoney ( ) ), screenWidth * 0.509 / 2, screenHeight * 0.022, screenWidth * 0.5 / 2, screenHeight * 0, tocolor ( 0, 0, 0, 255), 1, "bankgothic", "left", "top", false, false, true, true) 
    dxDrawText ( "#FFC000Twoje PP: #FF4000"..tostring ( getPlayerMoney ( ) ), screenWidth * 0.506 / 2, screenHeight * 0.02, screenWidth * 0.5 / 2, screenHeight * 0, tocolor ( 2, 2, 214, 255), 1, "bankgothic", "left", "top", false, false, true, true) 
end ) 

  
--Server 
function onLogin(previousAccount, currentAccount) 
    if not getAccountData(currentAccount, "p_money") or not getAccountData(currentAccount, "p_money") == nil then 
        setAccountData(currentAccount, "p_money", 0) 
    end 
    triggerClientEvent(source, "onSendMoneyToClient", source, getAccountData(currentAccount, "p_money)) 
end 
addEventHandler("onPlayerLogin", root, onLogin) 
  
  
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 
  
  
function getpoints ( player, command) 
local gPlayerAccount = getPlayerAccount(player) 
    outputChatBox(tostring(getAccountData ( gPlayerAccount, "p_money" ))) 
end 
addCommandHandler ( "getp", getpoints ) 
  
  
 

EDITED.

The rest you can do by yourself, too tired now atm. Try atleast to understand it..

Link to comment

Server-side:

function saveMoney(tPlayer) 
    if (tPlayer ~= nil) then 
        source = tPlayer 
    end 
    local gAccount = getPlayerAccount(source) 
    if (gAccount ~= false) then 
        local gMoney = getElementData(source, "p_money") 
        if (gMoney ~= false) then 
            setAccountData(gAccount, "p_money", gMoney) 
        end 
    end 
end 
  
addEvent("onRequestSaveMoney", true) 
addEventHandler("onRequestSaveMoney", getRootElement(), saveMoney) 
  
function setMoney(previousAccount, currentAccount) 
    local gMoney = getAccountData(currentAccount, "p_money") 
    if (gMoney ~= false) then 
        setElementData(source, "p_money", gMoney) 
    else 
        setElementData(source, "p_money", 0) 
    end 
end 
  
addEventHandler("onPlayerLogin", getRootElement(), setMoney) 

You can now work with 'setElementData and 'getElementData'. As soon as you set the money to the player's account in Client-side, then just use this code to save the money to the player's account:

triggerServerEvent("onRequestSaveMoney", getLocalPlayer()) 

As soon as the player logs in, then the money is automatically set.

If you want to save the money via Server-side, then use:

saveMoney(Fill-in-player-element-HERE) 

Try to study it, next time you are going to do it by yourself most of the time, instead of let everything done for you by someone else.

Link to comment

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