Erhabi Posted April 13, 2010 Share Posted April 13, 2010 hi all i have problem in my new scripting The problem starts when I want to send my money to another player. this is my scripting and this is the message for the problem i need help Link to comment
dzek (varez) Posted April 13, 2010 Share Posted April 13, 2010 dude! copy the script! don't post screenshots! and.. tell as which line is the 123 line that causing problem edit: and do rrr = tonumber(rrr) as the first line in your function edit2: and dont name your variables like that asm, rrr = this cant tell you anything name = getPlayerFromName(asm) this isnt nice too, "name" suggest a string, not a player element.. better name it: targetPlayer Link to comment
PacMan Posted April 13, 2010 Share Posted April 13, 2010 varez, you propose the wrong decision, when you convert nil in the number of remains nil. The error says that you compare the number with nil value, this happens when you do not enter the transfer amount. After the announcement of the function add "rrr = tonumber(rrr) or 0". Link to comment
Xierra Posted April 13, 2010 Share Posted April 13, 2010 ---!This is offtopic!--- To paste codes here, use: lua in square bracket and end it with "/" in front of "lua". That's the basic of BB code. Example (changeable radio on foot & in vehicle): function Radio (command, stationID) local result = setRadioChannel ( tonumber( stationID ) ) if result then -- if we had a valid ID outputChatBox ( "Changed your radio station to " .. getRadioChannelName ( tonumber ( stationID ) ) .. "!" ) else outputChatBox ( "Invalid radio station ID, valid ones are 0-12." ) end end addCommandHandler ("setradio", Radio) --How to use: setradio 5 Next time don't use screenshots for codes ok? Link to comment
karlis Posted April 13, 2010 Share Posted April 13, 2010 (edited) sory got it wrong(as usual ) Edited April 13, 2010 by Guest Link to comment
PacMan Posted April 13, 2010 Share Posted April 13, 2010 function Radio (command, stationID) local result = setRadioChannel ( tonumber( stationID ) ) if result then -- if we had a valid ID outputChatBox ( "Changed your radio station to " .. stationID .. "!" ) else outputChatBox ( "Invalid radio station ID, valid ones are 0-12." ) end end addCommandHandler ("setradio", Radio) --How to use: setradio 5 this was unefficent, no need for getting channel if you already have its variable, also string interpolation makes tonumber() automaticly In this case string interpolates C++, but not Lua, this must consider. Link to comment
Jason_Gregory Posted April 13, 2010 Share Posted April 13, 2010 Another example... (without Console Warnings) function Radio (command, stationID) if setRadioChannel (tonumber( stationID )) then outputChatBox ( "Changed your radio station to " .. getRadioChannelName (tonumber(stationID)) .. "!" ) else outputChatBox (stationID.." is a invalid radio station ID, valid ones are 0-12 !" ) end end addCommandHandler ("setradio", Radio) Link to comment
Erhabi Posted April 13, 2010 Author Share Posted April 13, 2010 thxxx all my scripting is work now but i have win one Question how can i show the money in scoreboard ??? Link to comment
karlis Posted April 13, 2010 Share Posted April 13, 2010 call(getResourceFromName("scoreboard"), "addScoreboardColumn", "money") --and use this when need change value setElementData( player, "money", value) ps:im not sure, isnt there build in money element data for player? Link to comment
karlis Posted April 13, 2010 Share Posted April 13, 2010 try setting element data first, then call scoreboard, and change data when money changes Link to comment
dzek (varez) Posted April 13, 2010 Share Posted April 13, 2010 varez, you propose the wrong decision, when you convert nil in the number of remains nil. nah, this wasn't about his actual problem that was just advice, becouse when you get a parametr from command it's string ? so givePlayerMoney(player, some_string_variable) could fail, right? i'm not sure about this, but its better to make tonumber when you are working with numbers Link to comment
Erhabi Posted April 13, 2010 Author Share Posted April 13, 2010 please give me example for it Link to comment
dzek (varez) Posted April 13, 2010 Share Posted April 13, 2010 call(getResourceFromName("scoreboard"), "addScoreboardColumn", "money") --and use this when need change value setElementData( player, "money", value) this is working.. ps:im not sure, isnt there build in money element data for player? nope,ive tested it Link to comment
karlis Posted April 14, 2010 Share Posted April 14, 2010 i bet he dont knows "player" and "value" need be replaced lol. Link to comment
Erhabi Posted April 14, 2010 Author Share Posted April 14, 2010 lol yea i don't know what value what is value? what do i replace with it? sorry my english is bad Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now