Forum

> > CS2D > Scripts > Why my script not working?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Why my script not working?

19 replies
To the start Previous 1 Next To the start

old Why my script not working?

Louie
User Off Offline

Quote
Spoiler >

So heres things i wanted to happen,everytime a player kills someone he gain +1 gold/Problem: it doesn't even show the hudtxt and i cant gain gold.2nd one-the !help and !buy commands i put in doesn't do anything,if a players says !buy then it will open up an menu of items(though i still haven't finished it),and if the player says !help then it would list commands(like !buy),Its not working though ,i didnt get any error messages.Help please.

old Re: Why my script not working?

TopNotch
User Off Offline

Quote
1
player(id,"exist")
Should be "exists".

Change your hudtxt2(id) to
1
parse('hudtxt2 '..id..' 49 "©255215Gold: '..gold[id]..'"540 348 0')
edited 1×, last 30.01.15 01:19:46 pm

old Re: Why my script not working?

Mora
User Off Offline

Quote
maybe so? idk, may be wrong.
i'll try to fix it as soon as possible.
edit:
maybe it's will be not wrong(edited full code):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function array(m,v)
     local a = {}
     for i = 1, m do
          a[i] = v
     end
     return a
end

gold = array(32,0)

addhook("kill","kills")
function kills(id)
   gold[id]=gold[id]+1
end

addhook("ms100","Gold")
function Gold(id)
     for _,id in pairs (player(0, "table")) do
parse('hudtxt2 '..id..' 0 "\169255195100Gold: '..gold[id]..' " 400 308')
	 end
end

addhook("say","help")
function help(id,txt)
	if txt=="!help" then
parse("sv_msg2 "..id.." say !buy to buy items at the cost of gold")
return 1
	elseif txt=="!buy" then
menu(id,"Special Items,Supply Drop|Cost-2,Airstrike|Cost-5,Bombing Run|Cost-8")
return 1
	end
end

addhook("menu","buyM1")
function buyM1(id,title,button)
if title == "Special Items" then
       if button == 1 then
       parse("equip "..id.." 76")
       end
end
end
I haven't made menu buy s**t, i think you can do by yourself..
edited 1×, last 30.01.15 01:16:05 pm

old Re: Why my script not working?

Bowlinghead
User Off Offline

Quote
Using © maybe causes bugs.
Use this instead:
1
parse('hudtxt2 '..id..' 0 "'string.char(169)..'169255195100Gold: '..gold[id]..' " 400 308')

old Re: Why my script not working?

RedizGaming
GAME BANNED Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--Variables
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end

gold=initArray(32)

--Script
addhook("kill","kills")
function kills(id)
	gold[id]=gold[id]+1
end

addhook("ms100","Gold")
function Gold()
	for _,id in pairs(player(0,'table')) do
		parse('hudtxt2 "..id.." 49 ©255215Gold: "..gold[id].." 540 348')
	end
end

addhook("say","help")
function help(,txt)
	if (txt=="!help") then
		parse("sv_msg2 "..id.." say !buy to buy items at the cost of gold")
	end
	if (txt=="!buy") then
		menu("..id..","Special Items,Supply Drop|Cost-2,Airstrike|Cost-5,Bombing Run|Cost-8")
	end
	return 1
end

addhook("menu","buyM1")
function buyM1(id,title,button)
	if title == "Special Items" then
		if button == 1 then
			parse("equip "..id.." 76")
		end
	end
end

try to use it

old Re: Why my script not working?

Louie
User Off Offline

Quote
user Mora has written
maybe so? idk, may be wrong.
i'll try to fix it as soon as possible.
edit:
maybe it's will be not wrong(edited full code):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function array(m,v)
     local a = {}
     for i = 1, m do
          a[i] = v
     end
     return a
end

gold = array(32,0)

addhook("kill","kills")
function kills(id)
   gold[id]=gold[id]+1
end

addhook("ms100","Gold")
function Gold(id)
     for _,id in pairs (player(0, "table")) do
parse('hudtxt2 '..id..' 0 "\169255195100Gold: '..gold[id]..' " 400 308')
	 end
end

addhook("say","help")
function help(id,txt)
	if txt=="!help" then
parse("sv_msg2 "..id.." say !buy to buy items at the cost of gold")
return 1
	elseif txt=="!buy" then
menu(id,"Special Items,Supply Drop|Cost-2,Airstrike|Cost-5,Bombing Run|Cost-8")
return 1
	end
end

addhook("menu","buyM1")
function buyM1(id,title,button)
if title == "Special Items" then
       if button == 1 then
       parse("equip "..id.." 76")
       end
end
end
I haven't made menu buy s**t, i think you can do by yourself..

Thx all for the replies,but its still not working

old Re: Why my script not working?

Dousea
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
gold = {}

for id = 1, 32 do
	gold[id] = 0
end

for none, hook in pairs({"kill", "always", "say", "menu"}) do
	addhook(hook, hook .. "hook")
end

function killhook(killer)
	gold[killer] = gold[killer] + 1
end

function alwayshook()
	for none, id in pairs(player(0, "tableliving")) do
		parse("hudtxt2 " .. id .. " 49 \"\169255215000Gold: " .. gold[id] .. "\" 540 348")
	end
end

function sayhook(id, text)
	if (text == "!help") then
		msg2(id, "Say \"!buy\" to buy special items which costs gold!")
	elseif (text == "!buy") then
		menu(id, "Special Items,Supply Drop|2 Golds,Airstrike|5 Golds,Bombing Run|8 Golds")
		
		return 1
	end
end

function menuhook(id, title, button)
	if (title == "Special Items") then
		if (button == 1) then
			parse("equip " .. id .. " 76")
		end
	end
end

old Re: Why my script not working?

Louie
User Off Offline

Quote
Ok theres one last problem i got.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function menuhook(id, title, button)
     if (title == "Special Items") then --Airstrike
          if (button == 2) and gold[id]>5 then
               parse("equip " .. id .. " 76")
               gold[id] = gold[id] - 5
     elseif (button == 2) and gold[id]<5 then
               msg2(id,"Not enough Gold")
     elseif (button == 1) and gold[id]>2 then --Supply Drop
               timer(5000,"parse","equip 61 " ..x.. " " ..y)
               gold[id] = gold[id] - 2
     elseif (button == 1) and gold[id]<2 then
              msg2(id,"Not enough Gold")
            end
      end
end
My problem here is even if i have 10 Gold i still cant buy anything,its supposed to be when i dont have the gold to buy it then it would show the message "Not enough gold" but it always shows that message,regardless even if i have more than enough gold for it.Wtf?
EDIT: Wtf for some reason that problem doesn't happen if i use it on a Dedicated server.
edited 1×, last 31.01.15 11:48:04 am

old Re: Why my script not working?

Bowlinghead
User Off Offline

Quote
When you use ">" it means it has to be higher.
If you use ">=" it means it has to be equal or higher.
So for button 2 you need at least 6 gold!
And at line 9 you wrote x and y. Are the defined?

old Re: Why my script not working?

Mora
User Off Offline

Quote
Full tested:
Work:
This ammo spawn on the position where you have used it!
Ex your pos is x3 and y7 you will press "buy shit ammo" and walk away, after 5 sec this item will spawn at x3 and y7, but not at your new position.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
addhook("menu","menuhook")
function menuhook(id, title, button, tilex, tiley)
    if (title == "Special Items") then
        if button == 1 then  --airstrike
			if gold[id]>=5 then
parse("equip " .. id .. " 76")
gold[id] = gold[id] - 5
            else msg2(id,"Not enough money, idiot!")
            end
        elseif button == 2 then
            if gold[id]>=2 then --Supply Drop
timer(5000,"parse","spawnitem 61 "..player(id,"tilex").." "..player(id,"tiley"))
gold[id] = gold[id] - 2
			else msg2(id,"Not enough money, idiot!")
			end
		end
	end
end
edited 4×, last 31.01.15 01:38:45 pm

old Re: Why my script not working?

Louie
User Off Offline

Quote
Ok thx,though another weird thing.
1
2
3
4
5
6
function alwayshook()
     for none, id in pairs(player(0, "tableliving")) do
         parse("hudtxt2 " .. id .. " 48 \"\169255215000Gold: " .. gold[id] .. "\" 540 348")
         parse("hudtxt2 " .. id .. " 49 \"\169255215000Level: " ..Levels[id].. " 540 400") 
     end
end
Only the first one shows in-game(Gold:) but the Level,it doesn't show,wtf?

old Re: Why my script not working?

Dousea
User Off Offline

Quote
1
2
parse("hudtxt2 " .. id .. " 49 \"\169255215000Level: " ..Levels[id].. " 540 400") -- wrong
parse("hudtxt2 " .. id .. " 49 \"\169215000Level: " .. Levels[id] .. "\" 540 400") -- right
Copy the "right" code.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview