Forum

> > CS2D > Scripts > A wrong with command script ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English A wrong with command script ?

20 replies
Page
To the start Previous 1 2 Next To the start

old A wrong with command script ?

Kirito2K
User Off Offline

Quote
Hi us ,
I edited file cs2d Levels and Exp script but i have a problem in a command..

The problem is some of the cmds don't work and when i try to use !info , !get_lvl , !set_lvl and !give_adm , the txt i sent don't disappear .
Script >

old Re: A wrong with command script ?

Bowlinghead
User Off Offline

Quote
in line 155 the "return 1" is outside of the ifs (means that you disable the whole chat).

Generally Cs2d parses different functions of the same addhook in a row - depending on their priority.
You should try to create 1 say-function instead of 3. Here is the reason:
Cs2d maybe goes to the function at 155 and forbids every command which means that you cannt even trigger the commands in the other say functions.

old Re: A wrong with command script ?

Bowlinghead
User Off Offline

Quote
Just copy and paste everything and delete commands which exists already and use your brain.
Or give each say-function an unique priority number.

Read carefully:
cs2d lua cmd addhook , cs2d lua hook say

Here is what I mean:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
--[[
	If player says something then hooks will executed in following order:
	say1,
	say2,
	because of their priorities.
]]--
addhook("say","say1",50) -- lower priority
function say1()
	return 1; -- blocks all communication | like in line 155
end
addhook("say","say2",100) -- higher priority.
function say2(id,t) -- wont be triggered anyway, because there will be never any chat parsed
	if (t=="Im a noob") then
		parse("equip "..id.." 45")
	end
end

Here is the solution to fix it:
1
2
3
4
5
6
7
addhook("say","say1")
function say1(id,t)
	if (t=="Im a noob") then
		parse("equip "..id.." 45")
		return 1; -- put return here
	end
end

Because you don´t have prioritys in your script at all we don´t know which say-hook will be executed first. You need to try something and look how it affects your script. (Trial and Error)
edited 2×, last 24.05.15 06:58:35 pm

old Re: A wrong with command script ?

Kirito2K
User Off Offline

Quote
here is the code :
Script >


PS : I didn't put the say funcs in one say hook bcs i'm afraid of getting more errors ..

old Re: A wrong with command script ?

Bowlinghead
User Off Offline

Quote
I summarized all 3 say-hooks into one firstly. Then I edited small things in your script.
Follow my comments in the script
Important part of the code >


Do you get any errors in the console?

old Re: A wrong with command script ?

Kirito2K
User Off Offline

Quote
It's not working , when i use !info i get this error :
LUA ERROR: sys/lua/lvl_exp.lua:150: bad argument #1 to 'player' (number expected, got nil)
and that line is
1
msg2(id,"©000100255"..player(_t2,"name").." has "..level[_t2].." level , "..exp[_t2].." exp and "..money[_t2].." money.")

And the !set_lvl , !give_lvl and !give_adm aren't working , i didn't get any error when i tried them .

Also i can see the txt when i say !info , !set_lvl , !give_lvl and !give_adm.

old Re: A wrong with command script ?

Bowlinghead
User Off Offline

Quote
@user Danilwra:
cs2d lua cmd addhook
You are able to use multiple hook functions.

For !info you also need to write the ID. Because you use "_t2" as player-ID and not "id".
To prevent this error write this under your _t2/_t3 declaration.
1
2
3
4
if (_t2 == nil) or (_t3 == nil) then -- if parameter not found
	msg2(id,"You did not used the correct parameter!") -- give error
	return 1;
end

Did you installed other scripts?

old Re: A wrong with command script ?

Kirito2K
User Off Offline

Quote
@user Danilwra: You didn't read what i said , look that 3 hooks came with that script i edited , stop just annoying me , if u know how to script then show me ur skills!

@user Bowlinghead: ok i will try that , and i didn't install any other scripts ..

/Edit : After trying i got error when i say !info without id after it
LUA ERROR: sys/lua/lvl_exp.lua:154: bad argument #1 to 'player' (number expected, got nil)
and even if i put a id after !info it don't work and i can see the txt
edited 1×, last 25.05.15 10:24:36 am

old Re: A wrong with command script ?

Ridho
User Off Offline

Quote
user Kirito2K maybe this?
I add some code to detect there's player or no
1
2
3
4
5
6
7
8
...
elseif txt == "!info" then
  if _t2~=nil and player(_t2,"exist") then
    msg2(id,"©000100255"..player(_t2,"name").." has "..level[_t2].." level , "..exp[_t2].." exp and "..money[_t2].." money.")
    return 1;
  end
else
...

untested but I think it works
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview