Jump to content

[Help] problem in my scripting :(


Erhabi

Recommended Posts

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 post

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 post

---!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 post
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 post

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

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