Jump to content

addEventHandler("onMoneyChange",..


BriGhtx3

Recommended Posts

Posted

Is it possible to create something that when the amount of money changes, it automaticly saves it?

I know that I can use a timer, but I mean sth like a handler

Currently working on gamemodes :

  • Reallife Script 70%
  • Breakout Script 10%
Posted

Well you can make for yourself too ..

Here are is my suggestion :

onClientRender 

You use this as a event handler , for the function , and you must script that everytime it saves the amount of the money

My Projects!

No one.

Posted

Here

function DXdraw() 
sWidth, sHeight = guiGetScreenSize() 
dxDrawText("Money "..tostring (getPlayerMoney(getLocalPlayer()),40,40,sWidth,sHeight,tocolor(0,255,0,255),1.5,"pricedown","right","top",false,false,false) 
end 
addEventHandler("onClientRender", getRootElement(), DXdraw) 

Posted

New problem :

I'm trying to show the players country but it always returns false.

function setLand() 
    local flag = exports['admin']:getPlayerCountry ( source ) 
    outputChatBox(tostring(flag)) 
    if flag then 
        setElementData(source,"Land",":admin/client/images/flags/"..flag..".png") 
    else 
        setElementData(source,"Land","N/A") 
    end 
end 
addEventHandler("onPlayerJoin",getRootElement(), setLand) 

The country is always set to N/A. I'm living in Germany :/

Currently working on gamemodes :

  • Reallife Script 70%
  • Breakout Script 10%
Posted

I already did it, but it never worked.

Edited line 705 added if column.name....

But it still doesn't show it, neither put out the country.

Currently working on gamemodes :

  • Reallife Script 70%
  • Breakout Script 10%
Posted

Money doesn't change out of the blue..

Money only changes when you tell the script to use setPlayerMoney, givePlayerMoney or takePlayerMoney

Everytime you use either of those functions, launch your own custom event "onMoneyChange", eventually passing the current money or whatever you like as parameters.

use triggerEvent()

https://wiki.multitheftauto.com/wiki/TriggerEvent

E.g: In case you use givePlayerMoney(player, 300), do this afterwards: triggerEvent ('onMoneyChange', player, getPlayerMoney(player))

PS: You can scrap passing getPlayerMoney, I'm just showing an example

Posted
local oldMoney = getPlayerMoney() 
  
function renderMoney() 
    newMoney = getPlayerMoney() 
    if ( tonumber(newMoney) ~= tonumber(oldMoney) ) then 
         triggerEvent("onClientMoneyChange",localPlayer,oldMoney,newMoney) 
         oldMoney = newMoney 
    end 
end 
addEventHandler("onClientRender",root,renderMoney) 
  
addEvent("onClientMoneyChange",true) 
addEventHandler("onClientMoneyChange",root, 
function (old, new) 
    outputChatBox(tostring(old) ..": ".. tostring(new)) 
end) 

Seems to work just fine.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Sure, if it works without any problem, then I see no problem on someone using it.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)

Client

addEvent( "onClientMoneyChange",true ) 
  
addEventHandler( "onClientMoneyChange",root, 
    function( oldMoney,newMoney ) 
        -- .... 
    end 
) 
     
function _givePlayerMoney( ... ) 
    local args = { ... } 
    if type( args[1] ) == "number" then 
        if triggerEvent( "onClientMoneyChange",localPlayer,getPlayerMoney( ),args[1] ) and 
        givePlayerMoney( ... ) then 
            return true 
        end 
        return false     
    end 
end 

Edited by Guest

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

This is example with client side.

Server

addEvent( "onMoneyChange",true ) 
  
addEventHandler( "onMoneyChange",root, 
    function( oldMoney,newMoney ) 
        -- .... 
    end 
) 
     
function _givePlayerMoney( ... ) 
    local args = { ... } 
    if isElement( args[1] ) and type( args[2] ) == "number" then 
        if triggerEvent( "onMoneyChange",args[1],getPlayerMoney( args[1] ),args[2] ) and 
        givePlayerMoney( ... )  
        then 
            return true 
        end 
        return false 
    end 
end 

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

Solidsnake, just out of curiosity, why did u add this line?

if (oldMoney < newMoney) then 

surely with that it only works if old money is less.. what if they have more?

shouldnt the function be:

function renderMoney() 
    newMoney = getPlayerMoney() 
    if ( tonumber(newMoney) ~= tonumber(oldMoney) ) then 
          triggerEvent("onClientMoneyChange",localPlayer,oldMoney,newMoney) 
          oldMoney = newMoney 
    end 
end 
addEventHandler("onClientRender",root,renderMoney) 

no offence intended... u do a great job on the forums helping people.

ScoobySig.gif

[UVA]Scooby

Founder Of UVA - Ultimate Vice Assassins

http://www.uvaclan.com/

Posted
Solidsnake, just out of curiosity, why did u add this line?
if (oldMoney < newMoney) then 

surely with that it only works if old money is less.. what if they have more?

shouldnt the function be:

function renderMoney() 
    newMoney = getPlayerMoney() 
    if ( tonumber(newMoney) ~= tonumber(oldMoney) ) then 
          triggerEvent("onClientMoneyChange",localPlayer,oldMoney,newMoney) 
          oldMoney = newMoney 
    end 
end 
addEventHandler("onClientRender",root,renderMoney) 

no offence intended... u do a great job on the forums helping people.

Yup, it was a mistake, this was part of one of my HUD system's, I guess it was intended to do something for the HUD ;)

Thanks for finding it out.

Corrected the script.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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