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 2192 193 194338 339 Next To the start

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
You made "car" a function and called it as table.
Function doesn't have index.
You should change function name and declare "car = {}"
edited 1×, last 21.04.10 05:25:58 pm

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Vectar666,
In that case he will get stack overflow.
He's clearly want to use index, not function.
At least, he should try to change "car" function name since Lua is first class and you can't use same name for function and variable.

old some questions.

wolfbr
User Off Offline

Quote
excuse me, it is possible to create different classes for teams?(so I learned to make class for both teams).

exemple: ct soldier = m4a1+usp+grenade
terror soldier = ak47+gloc+molotov

and it is possible to create subclass?
exemple> ct soldier = select your kit > m4a1+usp+grenade or spars12+DE+flashbang

----
and how to modify the weapons?
exemple: slow projectiles(like it>http://www.youtube.com/watch?v=u9npDVzBGjU&feature=player_embedded), cs Aiming System, reload time...
---
and how to edit the items that all begin?(pistol+knive)

thanks for your attention..

old Re: Lua Scripts/Questions/Help

Szkieletor
User Off Offline

Quote
I want to have 3 different cars to be available for buying using weiwen's car script. I tried to make 3 car scripts, giving each other a different image and speed. It didn't work even a little bit. So I tried changing few words in scripts, like in normal car is car, in slow car it's scar(SCAR MAXSPEED, SCAR IMAGE, etc.). The script worked partially, it says the car is bought(or not enough cash), but car don't spawn. Can you help me please?

old Re: Lua Scripts/Questions/Help

Soja1997
User Off Offline

Quote
Who can make RANDOM IMAGE?
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
CARS = {}
CARS_MAXSPEED = 25
CARS_ACCELERATION = function(speed) return speed/2 + 1 end
CARS_DECELERATION = function(speed) return -speed/2 - 1 end
CARS_IMAGEPATH = "gfx/Mod Car.png"
CARS_PRICE = 8000

if not addmoney then
     function addmoney(id, amount)
          if player(id, 'money') >= amount then
               parse(string.format("setmoney %i %i", id, player(id, 'money') - amount))
               return true
          end
          return false
     end
end

function addcar(x, y)
     table.insert(CARS, {x = x, y = y, speed = 0, image = image(CARS_IMAGEPATH, x, y, 0), rot = 0})
end

function carpos(car, x, y)
     local tilex, tiley = math.floor(car.x/32), math.floor(car.y/32)
     if not tile(tilex, tiley, 'walkable') then
          return false
     end
     for _, id in ipairs(player(0, 'table')) do
          if car.driver and car.driver ~= id and player(id, 'health') > 0 and math.abs(x - player(id, 'x')) < 16 and math.abs(y - player(id, 'y')) < 16 then
               parse(string.format("customkill %i Car %i", car.driver, id))
          end
     end
     car.x, car.y = x, y
     if car.driver then
          parse(string.format("setpos %i %i %i", car.driver, x, y))
     else
          imagepos(car.image, x, y, car.rot)
     end
     return true
end

addhook("ms100", "CARms100")
function CARms100()
     for id, car in pairs(CARS) do
          if car.driver then
               if not player(car.driver, 'exists') or player(car.driver, 'health') <= 0 then
                    car.driver = nil
                    car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
               else
                    car.rot = player(car.driver, 'rot')
                    car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_ACCELERATION(car.speed))
               end
          elseif car.speed > 0 then
               car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
          end
          if car.speed > 0 then
               local rot = math.rad(car.rot - 180)
               if not carpos(car, car.x - math.sin(rot)*car.speed, car.y + math.cos(rot)*car.speed) then
                    if car.driver then
                         parse(string.format("customkill %i Car %i", car.driver, car.driver))
                    end
                    freeimage(car.image)
                    parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver or 0))
                    parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
                    CARS[id] = nil
               end
          end
     end
end

addhook("use", "CARuse")
function CARuse(id,event,data,x,y)
     x, y = player(id, 'x'), player(id, 'y')
     for _, car in pairs(CARS) do
          if not car.driver and math.abs(car.x - x) < 16 and math.abs(car.y - y) < 16 then
               car.speedmod = player(id, 'speedmod')
               parse(string.format("speedmod %i 0", id))
               car.driver = id
               freeimage(car.image)
               car.image = image(CARS_IMAGEPATH, 1, 0, 200+id)
                break
          elseif car.driver == id then
               parse(string.format("speedmod %i %i", id, car.speedmod))
               car.driver = nil
               freeimage(car.image)
               car.image = image(CARS_IMAGEPATH, player(id, 'x'), player(id, 'y'), 0)
                break
          end
     end
end

addhook("die", "CARdie")
function CARdie(id,killer,weapon,x,y)
     x, y = player(id, 'tilex'), player(id, 'tiley')
     for id, car in pairs(CARS) do
          if car.driver == id then
               freeimage(car.image)
               parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver))
               parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
               CARS[id] = nil
                break
          end
     end
end

local bought, nomoney = "You have bought a car for $" .. CARS_PRICE .. ".", "You do not have enough money to buy a car. ($" .. CARS_PRICE .. ")"
addhook("say", "CARsay")
function CARsay(id,message)
     if message == "!car" then
          if addmoney(id, CARS_PRICE) then
               addcar(player(id, 'x'), player(id, 'y'))
               msg2(id, bought)
          else
               msg2(id, nomoney)
          end
          return 1
     end
end
CARS_IMAGEPATH = "gfx/Mod Car2.png"
CARS_IMAGEPATH = "gfx/Mod Car3.png"
CARS_IMAGEPATH = "gfx/Mod Car4.png"
CARS_IMAGEPATH = "gfx/Mod Car50.png"
edited 1×, last 21.04.10 09:15:47 pm

old Re: Lua Scripts/Questions/Help

Soja1997
User Off Offline

Quote
Who can make RANDOM IMAGE?
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
CARS = {}
CARS_MAXSPEED = 25
CARS_ACCELERATION = function(speed) return speed/2 + 1 end
CARS_DECELERATION = function(speed) return -speed/2 - 1 end
CARS_IMAGEPATH = "gfx/Mod Car.png"
CARS_PRICE = 8000

if not addmoney then
     function addmoney(id, amount)
          if player(id, 'money') >= amount then
               parse(string.format("setmoney %i %i", id, player(id, 'money') - amount))
               return true
          end
          return false
     end
end

function addcar(x, y)
     table.insert(CARS, {x = x, y = y, speed = 0, image = image(CARS_IMAGEPATH, x, y, 0), rot = 0})
end

function carpos(car, x, y)
     local tilex, tiley = math.floor(car.x/32), math.floor(car.y/32)
     if not tile(tilex, tiley, 'walkable') then
          return false
     end
     for _, id in ipairs(player(0, 'table')) do
          if car.driver and car.driver ~= id and player(id, 'health') > 0 and math.abs(x - player(id, 'x')) < 16 and math.abs(y - player(id, 'y')) < 16 then
               parse(string.format("customkill %i Car %i", car.driver, id))
          end
     end
     car.x, car.y = x, y
     if car.driver then
          parse(string.format("setpos %i %i %i", car.driver, x, y))
     else
          imagepos(car.image, x, y, car.rot)
     end
     return true
end

addhook("ms100", "CARms100")
function CARms100()
     for id, car in pairs(CARS) do
          if car.driver then
               if not player(car.driver, 'exists') or player(car.driver, 'health') <= 0 then
                    car.driver = nil
                    car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
               else
                    car.rot = player(car.driver, 'rot')
                    car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_ACCELERATION(car.speed))
               end
          elseif car.speed > 0 then
               car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
          end
          if car.speed > 0 then
               local rot = math.rad(car.rot - 180)
               if not carpos(car, car.x - math.sin(rot)*car.speed, car.y + math.cos(rot)*car.speed) then
                    if car.driver then
                         parse(string.format("customkill %i Car %i", car.driver, car.driver))
                    end
                    freeimage(car.image)
                    parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver or 0))
                    parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
                    CARS[id] = nil
               end
          end
     end
end

addhook("use", "CARuse")
function CARuse(id,event,data,x,y)
     x, y = player(id, 'x'), player(id, 'y')
     for _, car in pairs(CARS) do
          if not car.driver and math.abs(car.x - x) < 16 and math.abs(car.y - y) < 16 then
               car.speedmod = player(id, 'speedmod')
               parse(string.format("speedmod %i 0", id))
               car.driver = id
               freeimage(car.image)
               car.image = image(CARS_IMAGEPATH, 1, 0, 200+id)
                break
          elseif car.driver == id then
               parse(string.format("speedmod %i %i", id, car.speedmod))
               car.driver = nil
               freeimage(car.image)
               car.image = image(CARS_IMAGEPATH, player(id, 'x'), player(id, 'y'), 0)
                break
          end
     end
end

addhook("die", "CARdie")
function CARdie(id,killer,weapon,x,y)
     x, y = player(id, 'tilex'), player(id, 'tiley')
     for id, car in pairs(CARS) do
          if car.driver == id then
               freeimage(car.image)
               parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver))
               parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
               CARS[id] = nil
                break
          end
     end
end

local bought, nomoney = "You have bought a car for $" .. CARS_PRICE .. ".", "You do not have enough money to buy a car. ($" .. CARS_PRICE .. ")"
addhook("say", "CARsay")
function CARsay(id,message)
     if message == "!car" then
          if addmoney(id, CARS_PRICE) then
               addcar(player(id, 'x'), player(id, 'y'))
               msg2(id, bought)
          else
               msg2(id, nomoney)
          end
          return 1
     end
end
RANDOM IMAGEPATH
CARS_IMAGEPATH = "gfx/Mod Car.png"
CARS_IMAGEPATH = "gfx/Mod Car2.png"
CARS_IMAGEPATH = "gfx/Mod Car3.png"
CARS_IMAGEPATH = "gfx/Mod Car4.png"
CARS_IMAGEPATH = "gfx/Mod Car50.png"

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Soja1997: Stop posting the same shit over and over again, you're annoying me, if you want something fucking done you should do it by yourself instead of asking various times the same crap and saying "no one can do it?"

old Hello

Rafaelns18
User Off Offline

Quote
Hello guys, i need help, someone know how i can put on my serv, only authorized people using U.S.G.N, can join CT/TR?

english isnt my first languange so sorry, =/

see ya and thx

old closed Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
@Soja: Don't ever blindly copy others' work and ask for help without doing anything beforehand.


Here's a cleaner version of your code:
More >


Do the following replacements:

@@line 9 ---
CARS_IMAGEPATH = "gfx/Mod Car.png"
@@line 9 +++
CARS_IMAGEPATHS = {"gfx/Mod Car.png"}
for i = 1, 50 do table.insert(CARS_IMAGEPATHS, string.format("gfx/Mod Car%s.png", i)) end


@@line 21 in function addcar ---
     table.insert(CARS, {x = x, y = y, speed = 0, image = image(CARS_IMAGEPATH, x, y, 0), rot = 0})
@@line 21 +++
     math.randomseed(os.time())
     local img = CARS_IMAGEPATHS[math.random(50)]
     table.insert(CARS, {x = x, y = y, speed = 0, image = image(img, x, y, 0), rot = 0, imagepath = img})


@@line 79 in if of function CARuse ---
               car.image = image(CARS_IMAGEPATH, 1, 0, 200+id)
@@line 79 +++
               car.image = image(car.imagepath, 1, 0, 200+id)


@@line 86 in else of function CARuse ---
               car.image = image(CARS_IMAGEPATH, player(id, 'x'), player(id, 'y'), 0)
@@line 86 +++
               car.image = image(car.imagepath, player(id, 'x'), player(id, 'y'), 0)


The final code will look something like
More >

old Re: Lua Scripts/Questions/Help

Cure Pikachu
User Off Offline

Quote
Rafaelns18 has written
Hello guys, i need help, someone know how i can put on my serv, only authorized people using U.S.G.N, can join CT/TR?

english isnt my first languange so sorry, =/

see ya and thx

Looks like you havent seen the sample scripts.

More >

old Re: Lua Scripts/Questions/Help

Soja1997
User Off Offline

Quote
It can be done that you always buy other car? because almost all the time is the same
and When I have the car and somebody will kill me with car for me a model is staying
edited 1×, last 22.04.10 04:17:30 pm

old Re: Lua Scripts/Questions/Help

Szkieletor
User Off Offline

Quote
Szkieletor has written
I want to have 3 different cars to be available for buying using weiwen's car script. I tried to make 3 car scripts, giving each other a different image and speed. It didn't work even a little bit. So I tried changing few words in scripts, like in normal car is car, in slow car it's scar(SCAR MAXSPEED, SCAR IMAGE, etc.). The script worked partially, it says the car is bought(or not enough cash), but car don't spawn. Can you help me please?

I renew my question. I'm using the car same carscript as Soja.

old closed Re: Lua Scripts/Questions/Help

Soja1997
User Off Offline

Quote
Who can help with weiwen carscript
Spoiler >

Who can add Random IMAGE
CARS_IMAGEPATH = "gfx/a car1.png"
CARS_IMAGEPATH = "gfx/a car2.png"
CARS_IMAGEPATH = "gfx/a car3.png"
CARS_IMAGEPATH = "gfx/a car4.png"
CARS_IMAGEPATH = "gfx/a car5.png"
CARS_IMAGEPATH = "gfx/a car6.png"
CARS_IMAGEPATH = "gfx/a car7.png"
CARS_IMAGEPATH = "gfx/a car8.png"
CARS_IMAGEPATH = "gfx/a car9.png"
CARS_IMAGEPATH = "gfx/a car10.png"

edited 2×, last 22.04.10 07:41:29 pm

Admin/mod comment

okay.... this is just annyoing, super retarded and totally pointless. how often do you want to repeat that crap?! what are you thinking? repeat it once again to get the ban you deserve. /DC
To the start Previous 1 2192 193 194338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview