Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Scripts/Questions/Help

6,770 replies
Page
To the start Previous 1 2247 248 249338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
that hook doesn't pass any 'id' parameter
use a loop:
1
2
3
4
5
for id=1,32 do
	if player(id,"exists") then
		--insert your other code here
	end
end

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
What is the problem with this?
More >


It works except
1
2
t = {1,2,3,4,{5,6,7},8,9}
print(table.tostring(t))	--> {1234{567}89}
(No commas)

Edit
Nevermind i fixed it.

More >
edited 1×, last 01.09.10 02:36:19 am

old Re: Lua Scripts/Questions/Help

CJ7
BANNED Off Offline

Quote
Flacko has written
that hook doesn't pass any 'id' parameter
use a loop:
1
2
3
4
5
for id=1,32 do
	if player(id,"exists") then
		--insert your other code here
	end
end



for id 1,32 do is deprecated and rather inefficient. Look at the new player(0,'lalal') thingies to get MORE effiicient tables.

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
CJ7 has written
for id 1,32 do is deprecated and rather inefficient. Look at the new player(0,'lalal') thingies to get MORE effiicient tables.


Please, don't throw shit at me.
For loops don't iterate through a table if you don't use them for such thing so you can't deprecate them, the only drawback is to check for the existing player. Against the drawback of having to store the table for the existing players and indexing that table which causes a horrible look:

1
2
3
4
5
6
7
8
9
10
11
12
local a = player(0,"table")
for i=1,#a do
	player(a[i],"health")--stuff
end

--vs--

for i=1,32 do
	if player(i,"exists") do
		player(i,"health")--stuff
	end
end
Not to mention that if you're using ipairs() or pairs() you will get a slower code, as well as indexing a lua table is slower too.

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Yeah
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function dectohex(n)
	if type(n) == "string" then
		n=tonumber(n)
	end
	if not n then return nil end
	
	return string.format("0x%X", n) --RETURNS A STRING
end

function hextodec(n) --NEEDS A STRING STARTING WITH 0x or 0X
	if type(n) == string then
		return string.format("%i",n) --RETURNS A STRING
	end
end

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
Thanks.
I was trying to do it with tables of Hex digits and values, but you are good.

Here is an example of what I might do.
More >
edited 2×, last 01.09.10 05:38:42 am

old Re: Lua Scripts/Questions/Help

kalis
User Off Offline

Quote
heocon953 has written
help me if license==true
help me script save @ @
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local usgn, i = player(id,"usgn")
     if (usgn > 0) then
          local f = (io.open('sys/lua/license/'..player(id,"usgn")..'.txt','r'))
          if f then
               msg2(id,'Loading...^^!@C')
               for line in f:lines() do
                    i = 1
                    if (i == 1) then
                         rp_license[id] = value(line)
                    else
                         break
                    end
               end
               f:close()
               i = 1
          else
               msg2(id,'We are sorry, but failed to load save!@C')
          end
     else
          msg2(id,'Please Check Your U.S.G.N. Account Settings!@C')
     end
end
end
add+
1
2
3
4
5
6
7
8
9
function Array(size,value) 
	local array = {}
	for i = 1, size do
		array[i]=value
	end
	return array
end

rp_license = Array(32,false)


Help me pls ! !

old Re: Lua Scripts/Questions/Help

Jaso
BANNED Off Offline

Quote
Because i still havent got a answer i post it here again:

Can some one create a lua script so if a npc dies he does a trigger?

old Re: Lua Scripts/Questions/Help

RyceR
User Off Offline

Quote
try it, i dont know is this correct, but im low scripter
1
2
3
4
5
6
addhook("die","npc_die")
function npc_die()
	if player == NPC then
		parse("trigger YOUR TRIGGER HERE")
	end
end

old Re: Lua Scripts/Questions/Help

Jaso
BANNED Off Offline

Quote
Ok its fixed now but it doesnt seems to work i put the trigger again on the npc and let work on a dynwall but when i kill him the wall doesnt go away it just stays
edited 3×, last 01.09.10 11:02:47 am

old Re: Lua Scripts/Questions/Help

Soja1997
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("hit","healammo")
function healammo(victim,source,weapon)
     if player(victim,"team") == player(source,"team") then
          if weapon == 75 then
               parse("spawnitem 65 "..player(source,"tilex").." "..player(source,"tiley"))
               return 1
          elseif weapon == 86 then
               parse("spawnitem 61 "..player(source,"tilex").." "..player(source,"tiley"))
               parse("spawnitem 62 "..player(source,"tilex").." "..player(source,"tiley"))
               return 1
          end
     end
end
WHERE snowball crashes there appears bandage
and WHERE hutbomb crashes there appears primary and secondary ammo
AND I NEED Working UNLIMITED GUTBOMBS AND UNLIMITED SNOWBALLS SCRIPT

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
MSek has written
try it, i dont know is this correct, but im low scripter
1
2
3
4
5
6
addhook("die","npc_die")
function npc_die()
	if player == NPC then
		parse("trigger YOUR TRIGGER HERE")
	end
end


WTF?
Read the info on npcs @ cs2d.com! NPCs are NOT players, they are dynamic objects!!
Also where did you get the player value from? It's not a variable, it's a function!
And NPC? OMG!

But, I've done this before:
1
2
3
4
5
6
addhook("objectkill","_objectkill")
function _objectkill(id,pl)--Object ID, player id
	if object(id,"type") == 30 then --If npc
		parse("trigger YOURTRIGGERNAME")
	end
end

old Re: Lua Scripts/Questions/Help

Jaso
BANNED Off Offline

Quote
is it also possible to let him do two triggers?
Edit: Aight! it works now i can continue with nazi zombies!
Edit: O but wait if i do more npcs how put the scripts for them because script see,s all npcs the same?-Can some one answer this question please:(
edited 4×, last 01.09.10 11:41:07 am

old Re: Lua Scripts/Questions/Help

CJ7
BANNED Off Offline

Quote
Flacko has written
CJ7 has written
for id 1,32 do is deprecated and rather inefficient. Look at the new player(0,'lalal') thingies to get MORE effiicient tables.


Please, don't throw shit at me.
For loops don't iterate through a table if you don't use them for such thing so you can't deprecate them, the only drawback is to check for the existing player. Against the drawback of having to store the table for the existing players and indexing that table which causes a horrible look:

1
2
3
4
5
6
7
8
9
10
11
12
local a = player(0,"table")
for i=1,#a do
	player(a[i],"health")--stuff
end

--vs--

for i=1,32 do
	if player(i,"exists") do
		player(i,"health")--stuff
	end
end
Not to mention that if you're using ipairs() or pairs() you will get a slower code, as well as indexing a lua table is slower too.



Looping normally is indeed faster, but then this would definitly be the best option to loop. And who cares about the "looks" of a code? If it's about the looks then we should all use ipairs/pairs just because it's neater and shorter code.

1
2
3
4
5
local t = player(0,"table")

for i=1,#t do
	print(player(t[i],"health"))
end

This should be the fastest code then.

old Re: Lua Scripts/Questions/Help

kalis
User Off Offline

Quote
heocon953 has written
help me if license==true
help me script save @ @
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local usgn, i = player(id,"usgn")
     if (usgn > 0) then
          local f = (io.open('sys/lua/license/'..player(id,"usgn")..'.txt','r'))
          if f then
               msg2(id,'Loading...^^!@C')
               for line in f:lines() do
                    i = 1
                    if (i == 1) then
                         rp_license[id] = value(line)
                    else
                         break
                    end
               end
               f:close()
               i = 1
          else
               msg2(id,'We are sorry, but failed to load save!@C')
          end
     else
          msg2(id,'Please Check Your U.S.G.N. Account Settings!@C')
     end
end
end
add+
1
2
3
4
5
6
7
8
9
function Array(size,value) 
	local array = {}
	for i = 1, size do
		array[i]=value
	end
	return array
end

rp_license = Array(32,false)


help me ?? @ @

old spawnobject laser mine

VaiN
User Off Offline

Quote
Ahh this problem is giving me a headache.

I'm trying to replace a player-built laser mine with a neutral one. So far all i've managed to do is make it blow up in their face.

(amx2d)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function hook_build_arena(id,typ,x,y,mode,objectid)
	if arena.enabled == 1 then
		if typ == 20 then -- Mine
			parse("equip "..id.." 77")
		elseif typ == 21 then -- Laser Mine
			-- get rotation of the object by it's id
			local rot = object(objectid,"rot")
			print("spawnobject 21 "..x.." "..y.." "..rot.." "..mode.." 0 0")
			parse("spawnobject 21 "..x.." "..y.." "..rot.." "..mode.." 0 0")
			parse("equip "..id.." 87")
			return 1
		end
	end
end

First of all, I can't seem to get the rotation. It always returns the same float value regardless of the direction it's built. I tried getting the players rotation and checking it for the nearest 0, 90, 180, 270. But even that always returned 270 for some reason.

But my main question is, is there a way to not spawnobject instantly and have it still 'load' like they do when you place them in-game? Or is there a way to hook when a building is finished 'loading' and THEN replace it? If I can at least get it to not blow up in my face I can work from there. The angle doesn't seem to be the cause, because it even blows up with rotation of 0. I really don't want to bog down the CPU with huge arrays if I don't have to.
To the start Previous 1 2247 248 249338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview