Jump to content

Command Does Not Return Anything


Maccer.

Recommended Posts

I'm a lua starter, and I really suck at lua because the syntax is very unfamiliar for me. :| I usually code in more C-Style languages like C, PHP, and Pawn(sa-mp ftl.) Lua just turns my brain to mush. I do have coding experience, as a note. I used the freeroam script a temporary starter's template.

So the problem is, the code generates no errors, but the command returns no messages as the title says.

fr_client.lua:

function robPlayerMoneyCommand ( cmd, player )
--server.outputChatBox("You Have Robbed" .. , getRootElement(), 255, 255, 255, true)
--setElementPosition ( source, posX, posY, posZ )
iRandChance = math.random(0, 4)
if player then
	player = getPlayerFromNick(player)
	if player then
		if(iRandChance >= 2)
			server.outputChatBox("You Have Failed To Rob The Player!", getRootElement(), 255, 255, 255, false)
		end
	else
		server.outputChatBox("You have robbed the player!", getRootElement(), 255, 255, 255, false)
	end
else
	server.outputChatBox("Lolwut, an error occured.", getRootElement(), 255, 255, 255, false)
end
end

...

addCommandHandler('rob', robPlayerMoneyCommand)

Thanks, in advance. ;)

Link to comment

Have you turned debugscript on? Type 'debugscript 3' in the console while in-game.

You're using single quotes for your addCommandHandler rather than double quotes, that may be your issue...

You shouldn't really worry about Lua being different - the only real difference you need worry about is the syntax being a bit more 'english' - { and } replaced with do / end etc. Play with it for a few days and you'll find it very easy! Of course, there are some more advnaced parts of Lua, but you don't really need to worry about them until you're comfortable with the basics.

Link to comment

String constructors/destructors shouldn't have to do anything with that I think. What there is though, have you defined server.outputChatBox function? It should give you attempt to call nil value and attempt to index a nil value or something like that. And if it's client side, it won't show on server console, so you need debugscript.

Link to comment
Have you turned debugscript on? Type 'debugscript 3' in the console while in-game.

You're using single quotes for your addCommandHandler rather than double quotes, that may be your issue...

You shouldn't really worry about Lua being different - the only real difference you need worry about is the syntax being a bit more 'english' - { and } replaced with do / end etc. Play with it for a few days and you'll find it very easy! Of course, there are some more advnaced parts of Lua, but you don't really need to worry about them until you're comfortable with the basics.

I don't have ACL rights which I'm trying to set, but MTA doesn't provide the list of rights I can set. I also tried to use the admin script, but I can't understand how I set myself admin. :|

Link to comment

It looks to me that you've mixed up the command handler parameters in your function.

http://development.mtasa.com/index.php? ... andHandler

playerSource is the player that gave the command. theCommand is the command that was given. and you can put various arguements after that, say you were making a command to set your position somewhere, you would add x,y,z or something of that nature. just make player first and it should work fine.

also, server.outputchatbox is not necessary. All you need is outputChatBox()

I recommend you get familiar with the wiki. It has all the info you need to get started, such as scripting functions, how to manage your server and documentation on several things like Weapon IDs and whatever. development.mtasa.com

Link to comment
Alright, I've tried debugging, but no errors are returned.

Actually, I find this pretty hard to believe. Let me show you something in your code...

if player then                -- As you can see, if statements end with a "then" in Lua
if(iRandChance >= 2) -- That should include this one, but I don't see any.
           server.outputChatBox("You Have Failed To Rob The Player!", getRootElement(), 255, 255, 255, false)
end
else
        server.outputChatBox("You have robbed the player!", getRootElement(), 255, 255, 255, false)
end

The reason it "didn't show the error" is most likely that you forgot to restart the resource. These syntax errors report problems with the script at the time it's being started, like compilers do. If there's such an error, it only reports it as soon as the script is started, not later on anymore.

Also, it might have been a problem this new script wasn't loaded yet, because you didn't refresh/restart. In this case, it of course didn't have the ability to report the problem at all. :wink:

So just try "/restart freeroam" while in-game after you've edited something, it should solve the problem for as far as I can see.

Link to comment
Alright, I've tried debugging, but no errors are returned.

Actually, I find this pretty hard to believe. Let me show you something in your code...

if player then                -- As you can see, if statements end with a "then" in Lua
if(iRandChance >= 2) -- That should include this one, but I don't see any.
           server.outputChatBox("You Have Failed To Rob The Player!", getRootElement(), 255, 255, 255, false)
end
else
        server.outputChatBox("You have robbed the player!", getRootElement(), 255, 255, 255, false)
end

The reason it "didn't show the error" is most likely that you forgot to restart the resource. These syntax errors report problems with the script at the time it's being started, like compilers do. If there's such an error, it only reports it as soon as the script is started, not later on anymore.

Also, it might have been a problem this new script wasn't loaded yet, because you didn't refresh/restart. In this case, it of course didn't have the ability to report the problem at all. :wink:

So just try "/restart freeroam" while in-game after you've edited something, it should solve the problem for as far as I can see.

With the help of Vercetti1010, and the most sh*****st time wasting mistake ever... :roll: I've got it to work. Thanks, everyone. :) He mentioned some of those errors in my code.

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