Jump to content

Money scripting


[MT]Tobi

Recommended Posts

Hello I need help,

how can I script money to Classic Deathmatch on the cdm_ls.map !

I would buy things, gut without money it doesn't go!

This is what i have created:

function createBankAccount ( player, commandName )

cash = getPlayerMoney ( player )

--

playname = xmlLoadFile("playname.xml")

info = xmlCreateFile ( "playname.xml", "info" ) -- create the file "playname.xml" which looks like ""

xmlNodeSetAttribute ( info, "user" ) -- add a subnode , now we got ""

local banknode = xmlFindSubNode(playname, "user", 0)

xmlNodeSetAttribute(banknode, "bank", tostring(cash))

--xmlNodeSetValue ( bank, tostring( cash ) ) -- change the value, "0" --do not use

xmlSaveFile ( info ) -- save the file

xmlUnloadFile( info ) -- unload it after use

outputChatBox ("Banking...")

end

addCommandHandler ("bank", createBankAccount )

Link to comment

I would recommend to simply create the xml file in the resource folder by hand because i still cant get the xmlCreateFile function work dunno why... If you do so just create a new text file save it as playname.xml so it becomes an xml file and then write the root node in it like this:

<info> 
</info> 

and save the file.

Also i noticed that you tried to create a sub note with xmlNodeSetAttribute but you have to use xmlCreateSubNode. I edited your code so it should work but i neither know if i understood everything you said in the comments right nor i know if this would work because i havent got the time to test it.

Edited code:

  
function createBankAccount ( player, commandName ) 
    local cash = getPlayerMoney ( player ) 
    playname = xmlLoadFile("playname.xml") 
    local banknode = xmlCreateSubNode ( playname, "user" ) -- add a subnode <user>, now we got "<info><user></info>" 
    xmlNodeSetAttribute(banknode, "bank", tostring(cash)) -- change the value, "<info><user bank="(playerMoney)"></info>" --do not use 
    xmlSaveFile ( playname ) -- save the file 
    xmlUnloadFile( playname ) -- unload it after use 
    outputChatBox ("Banking...") 
  
end 
addCommandHandler ("bank", createBankAccount) 

i tested it and it seems to work pretty good. Here's the result

<info> 
   <user bank="50"/> 
</info> 
  
  

Link to comment
THX for help, but can you put it in an ZIP-Archive and send me?

I have made it, but when I type /bank in tha chatbox stands "Banking..." but nothing changed!

I have alway no money :(, please help,

thanks.....

You'll always have 0 until you give yourself money. It saves you money to the bank instead of giving you the money from bank.

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