Forum

> > CS2D > Scripts > Why doesn't it work?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Why doesn't it work?

47 replies
Page
To the start Previous 1 2 3 Next To the start

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
I play other games and I no longer script for cs2d as I'm working on other stuff so that's why.
You still have no idea why it's not working ?

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
Ok look. I tested the code below and it worked perfectly.
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
Milk = {}

addhook("leave","_leave")
function _leave(id)
     if Milk[id] ~= nil then
          freeimage(Milk[id])
          Milk[id] = nil
     end
end

addhook("startround","_startround")
function _startround(mode)
     for k,v in pairs (player(0,"tableliving")) do
          if Milk[v] == nil then
               Milk[v] = image("gfx/7hud/full.png",555,300,2)
               imagealpha(Milk[v],0.5)
          end
     end
end

addhook("endround","_endround")
function _endround(mode)
     for k,v in pairs (player(0,"table")) do
          if Milk[v] ~= nil then
               freeimage(Milk[v])
               Milk[v] = nil
          end
     end
end

P.S. I did change the image path for myself because I didnt have your file but it should work regardless (unless u got wrong path which since I saw the vid isn't a concern.)

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
I don't see anything that would mess up the scripts in either of codes. I suppose I can't help you any further.

old Re: Why doesn't it work?

Mami Tomoe
User Off Offline

Quote
user Rainoth has written
IMG:https://sc-cdn.scaleengine.net/i/5bff7a742d6703e997dd6db79bf391c23.png

Try that.


2 questions.
1. What is nil?
2. How to nil a ball?

Also another question, why does the football script spawn the green thing that's shooting lasers (volt something) and not a actual ball?

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
nil is nothing.
For example if I define
a = 5, it has a value (5) but if I define
b, it has no value, it's nil.
Also, since a has a value of 5, I can make it back into nothing by writing
a = nil.

What he meant was that the variable which stores the ball (you'll have to find that yourself, it's most likely a lua table to store ball's coordinates, behavior, etc) has to become nil (nothing).

For your last question, the script may spawn vortigaunts if there's a code to spawn vortigaunts instead of balls. That's the fault of the script and I can't help you with that. If you dislike the current football script, download another from file archive (it might even fix your current problems)

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
the dot (.) is referring to entries in table 'ball' so essentially it's how I said it, the table is 'ball' while it has characteristics like 'img' 'gfx' 'xstart' 'ystart' and others.
You have to do ball = nil
at the end of round (at least according to Yates)

old Re: Why doesn't it work?

Mami Tomoe
User Off Offline

Quote
@user Rainoth:
Something like that?
1
2
3
4
5
6
addhook(roundend,re)

function re,id,ball
for id = 1,32 do
ball = nil
end

That's all came up to my mind...

Admin/mod comment

You've forgot to add the Code tag for this piece of code. Added! /user GeoB99

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
if you don't already have an endround hook then yes (although the one you wrote is written incorrectly).

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
Read tutorials and the code of others.
In this case, it'll be faster to read, learn and understand this:
1
2
3
4
addhook("endround","er") -- both hooks and function names are texts so you need strings. Strings need quotes (') or (")
function er(mode) -- endround hook has mode argument which you don't need but should write to better understand what the hook provides and what it doesn't
	ball = nil -- tab each new level (function is start so lvl 0, IFs add more depth (level 1,2,3 and so on but you dont have them so tab the declaration once)
end

old Re: Why doesn't it work?

Mami Tomoe
User Off Offline

Quote
@user Rainoth: Thanks =D

user Rainoth has written
Ok look. I tested the code below and it worked perfectly.
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
Milk = {}

addhook("leave","_leave")
function _leave(id)
     if Milk[id] ~= nil then
          freeimage(Milk[id])
          Milk[id] = nil
     end
end

addhook("startround","_startround")
function _startround(mode)
     for k,v in pairs (player(0,"tableliving")) do
          if Milk[v] == nil then
               Milk[v] = image("gfx/7hud/full.png",555,300,2)
               imagealpha(Milk[v],0.5)
          end
     end
end

addhook("endround","_endround")
function _endround(mode)
     for k,v in pairs (player(0,"table")) do
          if Milk[v] ~= nil then
               freeimage(Milk[v])
               Milk[v] = nil
          end
     end
end

P.S. I did change the image path for myself because I didnt have your file but it should work regardless (unless u got wrong path which since I saw the vid isn't a concern.)


Can you make this code work for new players too? Cause peoples who joined after the round restart cant see it...
edited 1×, last 21.09.15 08:32:08 pm
To the start Previous 1 2 3 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview