Forum

> > CS2D > Scripts > does not return the value
Forums overviewCS2D overview Scripts overviewLog in to reply

English does not return the value

9 replies
To the start Previous 1 Next To the start

old does not return the value

Hazzard
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
addhook("startround","blq_startround")
addhook("walkover","blq_walkover")

function blq_startround()
local rndm = math.random(1,3)
	if rndm==1 then
		blq_walkover()
		msg ("©255000000 ¡¡¡ ROUND KNIFE !!!@C")
	else
		return nil
	end
end

function blq_walkover(id,iid,type)
	if (type==35) then
		return 1
	else
		return 0
	end
end

I do not understand why it returns the value. If the awp round KNIFE are blocked, and if not, you can grab .. Someone could help me? I just need to make me see my mistake ..

old Re: does not return the value

Rainoth
Moderator Off Offline

Quote
you should look at CS2D walkover hook. If you study arguments properly, you should see that iid is the iid of item which you walkover, yet you're checking if it's type 35 not the actual item.

old Re: does not return the value

Avo
User Off Offline

Quote
By the way:

What is sense in
return nil

?

"Nil" means nothing, so all functions return "nil" if nothing is stated.

old Re: does not return the value

Hazzard
User Off Offline

Quote
First of all, thank you all for responding.. I was reviewing the code and change some things, but I still do not understand what's wrong ..

Regarding the return nil, I want to return the normal rounds .. What's the problem?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
addhook("startround","blq_startround")
addhook("walkover","blq_walkover")

function blq_startround()
local rndm = math.random(1,3)
	if rndm==1 then
		blq_walkover()
		msg ("©255000000 ¡¡¡ ROUND KNIFE !!!@C")
	else
		return
	end
end

function blq_walkover(id,iid)
	if (iid==35) then
		parse("strip "..id.." 50")
		return 1
	else
		return 0
	end
end

old Re: does not return the value

DC
Admin Off Offline

Quote
What do you want to achieve with that code?

In line 7 you are calling the walkover function without passing any parameters. So both id and iid will be nil (=will not have any value at all). The parse statement in line 16 will never ever be executed because the condition in line 15 is always false.

You can call functions that are attached to hooks manually but they only have parameter values when they are called by the game itself / the event which triggers them

old Re: does not return the value

Hazzard
User Off Offline

Quote
user DC has written
What do you want to achieve with that code?

In line 7 you are calling the walkover function without passing any parameters. So both id and iid will be nil (=will not have any value at all). The parse statement in line 16 will never ever be executed because the condition in line 15 is always false.

You can call functions that are attached to hooks manually but they only have parameter values when they are called by the game itself / the event which triggers them


Thank you very much for answering DC. What I want to achieve is that in a knife round the awp be blocked, if the common round to continue normal ..

Spoiler >


I see you had a lot of mistakes in the script. Here's a little more orderly, but still does not work and do not understand why. In that I'm wrong?

PD:sorry if you do not understand some things, the translator is half bad ..

Admin/mod comment

Please always use the code tag when showing code. Spoiler is no suitable replacement because it has no line numbers. You can also put code tags in spoiler tags /DC

old Re: does not return the value

Alistaire
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
forcedSets = {
	[1] = {'50', 'Knife round'},
	[2] = {'35, 50', 'Normal round'}
	--You can add more sets here
}

currentSet = 0

addhook('spawn', 'spawnHook')
addhook('startround_prespawn', 'prespawnHook')

function spawnHook(id)
	return forcedSets[currentSet][1]
end

function prespawnHook()
	currentSet = math.random(1, #forcedSets)
	msg(forcedSets[currentSet][2]..'!')
end

old Re: does not return the value

DC
Admin Off Offline

Quote
@user Hazzard: Take a look at user Alistaire's solution. You didn't really fix the problem in your code you just moved it to another position. Now you are passing id and iid but those variables are never declared anywhere so they are still always nil. Variables don't exist unless they are defined by yourself or they are provided by CS2D when using functions that are called by game events/hooks

old Re: does not return the value

Hazzard
User Off Offline

Quote
user Alistaire has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
forcedSets = {
	[1] = {'50', 'Knife round'},
	[2] = {'35, 50', 'Normal round'}
	--You can add more sets here
}

currentSet = 0

addhook('spawn', 'spawnHook')
addhook('startround_prespawn', 'prespawnHook')

function spawnHook(id)
	return forcedSets[currentSet][1]
end

function prespawnHook()
	currentSet = math.random(1, #forcedSets)
	msg(forcedSets[currentSet][2]..'!')
end


Thank you very much for helping Alistaire. This very cute the code, but I've left exorbitant(desorbitado in spanish), as the awp are taken from the floor.. Might explain how to block items from the floor? the rest of the code I understand perfectly ..

user DC has written
@user Hazzard: Take a look at user @user Alistaire's solution. You didn't really fix the problem in your code you just moved it to another position. Now you are passing id and iid but those variables are never declared anywhere so they are still always nil. Variables don't exist unless they are defined by yourself or they are provided by CS2D when using functions that are called by game events/hooks


I'm sorry, I thought that since they are defined in CS2D, or so I understood .. keep working until it comes out ..

old Re: does not return the value

Alistaire
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
forcedSets = {
	[1] = {'50', 'Knife round'},
	[2] = {'35, 50', 'Normal round'}
	--You can add more sets here
}

currentSet = 0

addhook('walkover', 'walkoverHook')
addhook('spawn', 'spawnHook')
addhook('startround_prespawn', 'prespawnHook')

function walkoverHook(id)
	return 1
end

function spawnHook(id)
	return forcedSets[currentSet][1]
end

function prespawnHook()
	currentSet = math.random(1, #forcedSets)
	msg(forcedSets[currentSet][2]..'!')
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview