Forum

> > CS2D > Scripts > Image at a player when using a menu button?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Image at a player when using a menu button?

10 replies
To the start Previous 1 Next To the start

old Image at a player when using a menu button?

Louie
User Off Offline

Quote
In a script im making i want to make players to be able to use drones,so to do that i want to:
When a player uses a Menu button then an image gets attached to the player then after a certain time limit(like 1 minute) then the player gets re-spawned and the image removed.
Now about the movement:
I want that when the player is using the drone that player can pass thru walls and that player constanly get teleported(i think using "setpos"?) like 16 pixels forward(the direction depends on the players rotation)
How do i do those things? Thx in advance.

old Re: Image at a player when using a menu button?

Rainoth
Moderator Off Offline

Quote
To get what you need :

1. You learn basic trigonometry
2. You apply your new knowledge in scripting
3. You get the script

OR

1. You use the search function and stop making useless threads.

old Re: Image at a player when using a menu button?

Louie
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
addhook("menu","Drone")
function Drone(id,title,button)
if title == "Predator Drone" then
    if button == 1 then
      for i = 1,32 do
       image("gfx/Aircraft/Predator Drone.png",1,0,100 + i)
         end
      end
   end
end
I tried it but it doesn't show the image,the title was correct the image file path was also correct but still nothing

old Re: Image at a player when using a menu button?

Louie
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
addhook("menu","Drone")
function Drone(id,title,button)
if title == "Predator Drone" then
    if button == 1 then
      for i = 1,32,1 do
       id = image("gfx/Aircraft/Predator Drone.png",1,0,100 + i)
          
         end
      end
   end
end
Ok so the image is now showing but now all the players get the image and also even when i die and respawn i still have the image wtf.

EDIT: http://www.unrealsoftware.de/forum_posts.php?post=316068 Well at least now i get the teleporting thing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("serveraction","propel")
function propel(id,a)
     if a==1 then
          local distance = 32
          local rot = player(id,"rot")
          local x = player(id,"x") + math.cos(math.rad(rot)-math.pi/2) * distance
          msg("math.cos(math.rad(rot)-math.pi/2) = "..math.cos(math.rad(rot)-math.pi/2))
          local y = player(id,"y") + math.sin(math.rad(rot)-math.pi/2) * distance
          msg("math.sin(math.rad(rot)-math.pi/2) = "..math.sin(math.rad(rot)-math.pi/2))
          msg("x displacement = "..x-player(id,"x"))
          msg("y displacement = "..y-player(id,"y"))
          parse("setpos "..id.." "..x.." "..y)
     end
end
I'll just edit it a bit.I'll also study and examine it so if i have a future problem similar to this then i will know what to do. ,now the only problem i have left is the image thing
edited 1×, last 11.02.15 11:49:00 am

old Re: Image at a player when using a menu button?

Rainoth
Moderator Off Offline

Quote
You're getting the image because you're looping every player when you're setting it up. You wrote it yourself so I assumed you wanted it that way. Don't use the loop if you need it only for one person. Also, since the image is set, you're not doing anything with it afterwards so of course it'll stay even after you respawn. You'll have to free it on death if you want it to disappear.

old Re: Image at a player when using a menu button?

Louie
User Off Offline

Quote
Lol i don't how this happened,the rotation of the image is opposite to the rotation of the player help please
IMG:https://i.imgur.com/t88ONEa.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("menu","Drone")
function Drone(id,title,button)
if title == "Predator Drone" then
    if button == 1 then
insidedrone[id] = insidedrone[id] + 1
       local img = image("gfx/MrZombie/Predator Drone.png",1,0,200 + id)
       local x  = player(id,"x")
       local y  = player(id,"y")
       local plrot = player(id,"rot")
       imagepos(img,"..x..","..y..","..plrot..")
       parse("speedmod "..id.." -100")          
      end
   end
end
thats the code.EDIT: and speedmod doesn't work wtf

old Re: Image at a player when using a menu button?

Louie
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
addhook("serveraction","flydrone")
function flydrone(id,key)
if key == 3 and insidedrone[id] == 1 then
       local flydistance = 32
       local rot = player(id,"rot")
       local x = player(id,"x") + math.cos(math.rad(rot)-math.pi/2) * flydistance
       local y = player(id,"y") + math.sin(math.rad(rot)-math.pi/2) * flydistance
       parse("setpos "..id.." "..x.." "..y)
    end
end
Yeah so this works but i want it to be that it will always happen
i tried this but i get an error:'player' (number expected,got string)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function array(m, h)
	local f = {}
	for id = 1, m do
		f[id] = h
	end
return f
end

pl = array(32, 0)

addhook("ms100","fly")
function fly()
          local distance = 3.2
          local rot = player(pl,"rot")
          local x = player(id,"x") + math.cos(math.rad(rot)-math.pi/2) * distance
          local y = player(id,"y") + math.sin(math.rad(rot)-math.pi/2) * distance
          parse("setpos "..pl.." "..x.." "..y)
end

old Re: Image at a player when using a menu button?

Yazir
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function array(m, h) -- initiating looks ok
     local f = {}
     for id = 1, m do
          f[id] = h
     end
return f
end

pl = array(32, 0)

addhook("ms100","fly")
function fly() -- if you want to pin it to the player, use on spawn hook
          local distance = 3.2
          local rot = player(pl,"rot") -- there's no such variable like pl, rot is ok
          local x = player(id,"x") + math.cos(math.rad(rot)-math.pi/2) * distance -- idk why there is pl var line above and here it's id(and below), you have to initiate it
          local y = player(id,"y") + math.sin(math.rad(rot)-math.pi/2) * distance -- idk if those sin and rad math stuff works, i didn't had them in school yet
          parse("setpos "..pl.." "..x.." "..y) -- pl var again
end

old Re: Image at a player when using a menu button?

Louie
User Off Offline

Quote
@user Yazir: the sin,cos works but idk why it wont work with "ms100" hook it works when i use "serveraction" hook.
EDIT: Nvm,found it out.
1
2
3
4
5
6
7
8
9
10
11
12
addhook("ms100","xD")
function xD()
for _, id in ipairs(player(0,"table")) do
    if insidedrone == 1 then
          local distance = 12
          local rot = player(id,"rot")
          local x = player(id,"x") + math.cos(math.rad(rot)-math.pi/2) * distance
          local y = player(id,"y") + math.sin(math.rad(rot)-math.pi/2) * distance
          parse("setpos "..id.." "..x.." "..y)         
end
end
end
EDIT2: hmm it doesn't work when i put in the variable "insidedrone" i use that variable to check if the player is using the drone or not.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
insidedrone = {}

for id = 1,32 do
insidedrone[id] = 0

addhook("menu","Drone")
function Drone(id,title,button)
if title == "Predator Drone" then
    if button == 1 and insidedrone[id] == 0 then
    insidedrone[id] = insidedrone[id] + 1
       local img = image("gfx/MrZombie/Predator Drone.png",1,0,200 + id)
       parse("speedmod "..id.." -100")
    timer(40000,"freeimage",id)
       insidedrone[id] = insidedrone[id] - 1         
      end
   end
end
then after 40 seconds(or 40000 miliseconds) then the player cant use the drone and the image is taken away and insidedrone[id] becomes 0,but when i use the button then the image is placed the speedmod -100 works but ms100 thing doesn't work(the ms100 from the first edit).
edited 2×, last 13.02.15 11:54:31 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview