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 2193 194 195338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Soja1997
User Off Offline

Quote
Spoiler >

Bad Argument#1 to image Why?
edited 2×, last 22.04.10 09:18:26 pm

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Soja1997 has written
Bad Argument#1 to image Why?

I said it to you on PM.
CARS3_IMAGEPATH - delete "3" in your variable.
Stop spamming with PMs

@Lee,
Did you locked your own post just for fun?
IMG:https://img717.imageshack.us/img717/706/titlei.th.png

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
It is working for me, you should randomize each time on adding the car.

Change this function.
1
2
3
function addcar(x, y)
	table.insert(CARS, {x = x, y = y, speed = 0, image = image("gfx/a car"..math.random(1,10)..".png", x, y, 0), rot = 0})
end

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Blazzingxx has written
@Lee,
Did you locked your own post just for fun?
IMG:https://img717.imageshack.us/img717/706/titlei.th.png


I was wondering if anyone would've noticed it

@Soja1997: notice that the imagepath is not linked on line 79 and 86:

car.image = image(CARS_IMAGEPATH, 1, 0, 200+id)
...
car.image = image(CARS_IMAGEPATH, player(id, 'x'), player(id, 'y'), 0)

Make sure that you compensate for this since the math.random function is indeterministic.

old Re: Lua Scripts/Questions/Help

Soja1997
User Off Offline

Quote
Even if for heap of 1000 cars and of it everyone will use will look the same
Spoiler >

PS. I use Translator ;s http://www.translatica.pl/

old Re: Lua Scripts/Questions/Help

gabpro
User Off Offline

Quote
After answering it can anyone answer the following question?

I'd like to know how to save a variable in a document(.txt) and load it later,for example save the mod's money...

PS:LOL,I'm using tradutor too

old Re: Lua Scripts/Questions/Help

Yrael
User Off Offline

Quote
hello scripters!
just a few problems... (i am very bad at scripting, i cannot make my own scripts, but i can edit premade scripts to better suit my needs)

so here is a script i got from the lua file section for cs2d:
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
addhook("serveraction","my_serveraction")
function my_serveraction(id,action)

	if action == 1 then
		shootFireball(id)
	end
end

rpiconst = 180 / math.pi
imagepath = "sys/lua/fbmod/fireball.png" -- path to image
speed = 100 --speed of fireball
dmg = 1000 --damage it does

function initArray(m,v)
     local array = {}
     for i = 1, m do
          array[i]=v
     end
     return array
end

fireball = {x = 0,y = 0,dir = 0,fid = 0,exists=0,rot = 0}
fireballs = initArray(32,fireball) -- each person can only have 1 fireball atm.

function shootFireball(id)
	if(fireballs[id].exists ~= 0) then
		freeimage(fireballs[id].fid)
	end
	fireballs[id] = {x = player(id,"x"),y = player(id,"y"),dir =toRad(player(id,"rot")),fid = 0,exists = 1,rot = player(id,"rot")}
	drawFireball(id)
end


function toRad(deg) -- from degrees to radian
	return (deg / rpiconst)
end

function collision(xpos,ypos,id)
	if((xpos > player(id,"x") - 30) and (xpos <  player(id,"x") + 30)) then
		if((ypos > player(id,"y") - 30) and (ypos <  player(id,"y") + 30)) then
			--msg("collision!")
			return true
		end
	end
	return false
end

function updateFireball(id) --update position, check for bounds
	fireballs[id].y = fireballs[id].y - (math.cos(fireballs[id].dir)*speed)
	fireballs[id].x = fireballs[id].x + (math.sin(fireballs[id].dir)*speed)

	local xpos = fireballs[id].x -- tired of typing the long thing ;P
	local ypos = fireballs[id].y -- ditto

	for i,v in ipairs(player(0,"table")) do -- collision
		if(i ~= id) then
			if(collision(xpos,ypos,i)) then
				parse("sethealth "..i.." "..(player(i,"health")-dmg))
			end
		end
	end


	if(fireballs[id].x > (map("xsize")*32) or fireballs[id].x < 0 or fireballs[id].y > (map("ysize")*32) or fireballs[id].y < 0) then --check for map boundaries
		fireballs[id].exists = 0
		freeimage(fireballs[id].fid)
	else
		imagepos(fireballs[id].fid,fireballs[id].x,fireballs[id].y,fireballs[id].rot)
	end
end

function drawFireball(id) -- draw and rotate.
	fireballs[id].fid=image(imagepath,fireballs[id].x,fireballs[id].y,1)
	imagepos(fireballs[id].fid,fireballs[id].x,fireballs[id].y,fireballs[id].rot)
end

addhook("ms100","my_ms100")
function my_ms100()
	for i,v in ipairs(fireballs) do
		if(v.exists==0) then
			return
		end
		updateFireball(i)
	end
end

now here i have some trouble, because i want to make it so that i can send multiple fireballs at a time... i can see line 22 and 23 are for that purpose. i tried deleting that line but the script wouldnt work, so i know that i need to edit the values. problem is i dont know which values to change and how high to put them
and if anybody knows how to make the fireballs disappear after a certain amount of time, that would be great

id also like to make a script that by pressing a server action button, you could teleport to your mouse cursor, i think that would be just too cool!!!

any help appreciated

old Re: Lua Scripts/Questions/Help

Heartless Soldier
User Off Offline

Quote
gabpro has written
After answering it can anyone answer the following question?

I'd like to know how to save a variable in a document(.txt) and load it later,for example save the mod's money...

PS:LOL,I'm using tradutor too


There are too much information in the forum about that ;), or in the download section, just search and you'll see

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Yrael:
You actually have to change the script a bit.
More >

old Re: Lua Scripts/Questions/Help

Anti
User Off Offline

Quote
Pls help me.. I don't see bug

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
function initArray(m,t)
 local array = {}
 for i = 1, m do
  if (t==nil) then
   array[i]=0
  else
   array[i]=t
  end
 end
 return array
end

speed_mvs = initArray(32)

function speed22_mvs(id) 
parse("hudtxt2 "..id.." 1 \"©000255000Moves: "..speed_mvs[id].."\" 425 400")
end 


addhook("move","MVS")
function MVS(p)
	speed_mvs[p]=speed_mvs[p]+1
	if speed_mvs[p]==1000  then
	parse("slay "..p)
	end
speed22_mvs(id) 
end

addhook("startround","speed_startround")
function speed_startround()
speed_mvs=0
speed22_mvs(id) 
end

To the start Previous 1 2193 194 195338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview