Lua based map objects, help! (BW related)
Author |
Message |
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Lua based map objects, help! (BW related)
A more efficient solution(just add one to the current teleporter number, if greater than list, teleport to one): Code: function Create(self) if (_teleporters == nil) then _teleporters = {self} else table.insert(_teleporters,self) end self.teledelaytimer = Timer(); self.teleactivate = nil; self.thistele = #_teleporters; end
function Destroy(self) table.remove(_teleporters,self) end
function Update(self) if(#_teleporters > 1) then for actor in MovableMan.Actors do if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0)then if not self.teleactivated then self.teleactivate = CreateAEmitter("Teleport Activation"); self.teleactivate.Lifetime = 2000; self.teleactivate.Pos = self.Pos; self.teleactivate:EnableEmission(true); MovableMan:AddParticle(self.teleactivate); self.teledelaytimer:Reset(); self.teleactivated = 1 else if self.teledelaytimer:IsPastSimMS(2000)then --TELEPORTATION HAPPENS HERE -- The below commented code has random teleport. --[[ local i = math.random(1,#_teleporters) while i == self.thistele do i = math.random(1,#_teleporters) end --]] --Below code is sequential teleport --[[ i = self.thistele + 1; if (i < #_teleporters) then i = 1; end --]] for oactor in MovableMan.Actors if (oactor.Pos.X >= _teleporters[i].Pos.X - 24) and (oactor.Pos.X <= _teleporters[i].Pos.X + 24) and (oactor.Pos.Y >= _teleporters[i].Pos.Y - 25) and (oactor.Pos.Y <= _teleporters[i].Pos.Y + 25) then oactor:GibThis(); _teleporters[i].teledelaytimer:Reset(); self.teleactivate.Lifetime = 2000; self.teleactivated = 0 end end actor.Pos = _teleporters[i].Pos
self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 2000; self.teleactivated = 0 end end end end if self.teledelaytimer:IsPastSimMS(3000) -- Sanity Check. then self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 2000; self.teleactivated = 0 end end end
|
Fri Apr 24, 2009 5:53 am |
|
|
piipu
Joined: Mon Jun 30, 2008 9:13 pm Posts: 499 Location: Finland
|
Re: Lua based map objects, help! (BW related)
Shouldn't this Code: if (i < #_teleporters) be that Code: if (i > #_teleporters) And what's the point of the sanity check thing? It just checks if the emitter still exists after a second of it's lifetime expiring, and if it does, sets it's lifetime to what it already is and resets the teledelaytimer. And you do that same thing when the actor is teleported. And your more efficient solution does exactly the same thing as mine did.
|
Fri Apr 24, 2009 12:31 pm |
|
|
numgun
Joined: Sat Jan 13, 2007 11:04 pm Posts: 2932
|
Re: Lua based map objects, help! (BW related)
Mail2345, that code doesnt teleport anything. It just does the effect at the start once and thats it. Theres something wrong with the structure of the code or something since it seems the teleporter only works once properly. It only once does the animation effect like it should and moves the actor to the next teleport in the list. Now I'm trying to get this new module to work, but I think I did it wrong: Its the slow motion field module. Stuff that goes in gets its speed reduced signicantly from what it was. What my code does is reduce the speed in a loop instead of once. So that means it basically stops everything instantly. Code: function Create(self) end
function Destroy(self) end
function Update(self) --First checks whether an actor or an item is within the box and slows them down to 10% velocity. Hooray maths! :D for actor in MovableMan.Actors do if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) then actor.Vel.Y = actor.Vel.Y * 0.1; actor.Vel.X = actor.Vel.X * 0.1; end end for item in MovableMan.Items do if (item.Pos.X >= self.Pos.X - 24) and (item.Pos.X <= self.Pos.X + 24) and (item.Pos.Y >= self.Pos.Y - 25) and (item.Pos.Y <= self.Pos.Y + 25) then item.Vel.Y = item.Vel.Y * 0.1; item.Vel.X = item.Vel.X * 0.1; end end for particle in MovableMan.Particles do if (particle.Pos.X >= self.Pos.X - 24) and (particle.Pos.X <= self.Pos.X + 24) and (particle.Pos.Y >= self.Pos.Y - 25) and (particle.Pos.Y <= self.Pos.Y + 25) then particle.Vel.Y = particle.Vel.Y * 0.1; particle.Vel.X = particle.Vel.X * 0.1; end end end How to make it so it only does the speed reduction only once? EDIT: Is there anything the opposite of "MovableMan:AddActor();" like "Delete actor" or something?
|
Fri Apr 24, 2009 7:38 pm |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Lua based map objects, help! (BW related)
Sorry, I will explain. Sanity check fixes bizarre jump back issue. And makes the teleporter shut down after it should. I made a lot of mistakes, this should work. Including accidental disabled teleport. And I do have some problems. Fixing: Code: function Create(self) if (_teleporters == nil) then _teleporters = {self} else table.insert(_teleporters,self) end self.teledelaytimer = Timer(); self.teleactivate = nil; self.thistele = #_teleporters; end
function Destroy(self) table.remove(_teleporters,self) end
function Update(self) if(#_teleporters > 1) then for actor in MovableMan.Actors do if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0)then if not self.teleactivated then self.teleactivate = CreateAEmitter("Teleport Activation"); self.teleactivate.Lifetime = 2000; self.teleactivate.Pos = self.Pos; self.teleactivate:EnableEmission(true); MovableMan:AddParticle(self.teleactivate); self.teledelaytimer:Reset(); self.teleactivated = 1 else if self.teledelaytimer:IsPastSimMS(2000)then --TELEPORTATION HAPPENS HERE local i = #_teleporters --Failsafe. -- The below commented code has random teleport. --[[ i = math.random(1,#_teleporters) while i == self.thistele do i = math.random(1,#_teleporters) end --]] --Below code is pair teleport --[[ if self.thistele%2 == 1 then i = self.thistele + 1; end if self.thistele%2 == 0 then i = self.thistele - 1; end if i > #_teleporters) --Abort teleport if unpaired then self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0 break end --]] --Below code is sequential teleport i = self.thistele + 1; if (i > #_teleporters) -- Kiosk keyboards suck. then i = 1; end for oactor in MovableMan.Actors if (oactor.Pos.X >= _teleporters[i].Pos.X - 24) and (oactor.Pos.X <= _teleporters[i].Pos.X + 24) and (oactor.Pos.Y >= _teleporters[i].Pos.Y - 25) and (oactor.Pos.Y <= _teleporters[i].Pos.Y + 25) then oactor:GibThis(); _teleporters[i].teledelaytimer:Reset(); -- Needed _teleporters[i].teleactivate.Lifetime = 1; _teleporters[i].teleactivated = 0 end end actor.Pos = _teleporters[i].Pos self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0 end end end end if self.teledelaytimer:IsPastSimMS(3000) -- Sanity Check. then self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0 end end end
And I'm not sure if you can add new values to an object in B23, but here is a try: Code: function Create(self) end
function Destroy(self) end
function Update(self) --First checks whether an actor or an item is within the box and slows them down to 10% velocity. Hooray maths! :D for actor in MovableMan.Actors do if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and item.slowed == nil then actor.Vel.Y = actor.Vel.Y * 0.1; actor.Vel.X = actor.Vel.X * 0.1; item.slowed = true. end end for item in MovableMan.Items do if (item.Pos.X >= self.Pos.X - 24) and (item.Pos.X <= self.Pos.X + 24) and (item.Pos.Y >= self.Pos.Y - 25) and (item.Pos.Y <= self.Pos.Y + 25) and item.slowed == nil then item.Vel.Y = item.Vel.Y * 0.1; item.Vel.X = item.Vel.X * 0.1; item.slowed = true; end end for particle in MovableMan.Particles do if (particle.Pos.X >= self.Pos.X - 24) and (particle.Pos.X <= self.Pos.X + 24) and (particle.Pos.Y >= self.Pos.Y - 25) and (particle.Pos.Y <= self.Pos.Y + 25) and particle.slowed == nil then particle.Vel.Y = particle.Vel.Y * 0.1; particle.Vel.X = particle.Vel.X * 0.1; particle.slowed = true; end end end
And if you wanted things to be re-slowed, use a timer.
|
Fri Apr 24, 2009 11:23 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Lua based map objects, help! (BW related)
Nope, can't apply variables to other objects. They delete them the next frame. You could try having an array that stores all the items that have gone in and out of the area, and check every Update if the object is still there. It would be a pain, but it would work. Also, just a warning, constantly cycling through every particle causes immense lag once digging or explosions start happening (on lower-end computers anyway), as you can see with Orbit Lands. In general, particles should be ignored unless absolutely necessary.
|
Fri Apr 24, 2009 11:55 pm |
|
|
numgun
Joined: Sat Jan 13, 2007 11:04 pm Posts: 2932
|
Re: Lua based map objects, help! (BW related)
Works slightly better now. After teleporting successfully to every teleport once with effects and stuff, it stops working as it should and it only teleports between the last and the first teleport you entered. Seriously guys. THE TELEPORTS WORK RIGHT ONLY ONCE, THE CODE IS BUILT SOMEHOW WRONG. I tried making some code myself, but then I managed to make CC crash completely and then lag like hell because of the effects spawning too early and then freezing in a wierd manner. Also I found another way to make the slow mo field work, its cool now. I just made the percentage to what the speed is decreaced much higher so now it gradually, but nicely slows the objects down without even needing to do it just once. Btw, I also ported the slow mo and the particle accelerator modules code to portable grenade versions. They turned out really good. The accelerator works like a hacky damage amplifier by throwing the thing infront of you where it will deploy a small acceleration field which doubles the mass and triples the velocity of the particles that travel through it. Very deadly. And same thing for the slow mo field. A throwable kit starts generating a slow mo field where everything is slowed down making stuff go really wacky. Suggest more ideas, these are really fun. EDIT: The latest teleport code. It had some bugs like a missing "do" at one part and then I added a cool effect that makes the actor flash white when the teleport is used. Code: function Create(self) if (_teleporters == nil) then _teleporters = {self} else table.insert(_teleporters,self) end self.teledelaytimer = Timer(); self.teleactivate = nil; self.thistele = #_teleporters; end
function Destroy(self) table.remove(_teleporters,self) end
function Update(self) if(#_teleporters > 1) then for actor in MovableMan.Actors do if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0)then if not self.teleactivated then self.teleactivate = CreateAEmitter("Teleport Activation"); self.teleactivate.Lifetime = 2000; self.teleactivate.Pos = self.Pos; self.teleactivate:EnableEmission(true); MovableMan:AddParticle(self.teleactivate); self.teledelaytimer:Reset(); self.teleactivated = 1 else if self.teledelaytimer:IsPastSimMS(2000)then --TELEPORTATION HAPPENS HERE local i = #_teleporters --Failsafe. -- The below commented code has random teleport. --[[ i = math.random(1,#_teleporters) while i == self.thistele do i = math.random(1,#_teleporters) end --]] --Below code is pair teleport --[[ if self.thistele%2 == 1 then i = self.thistele + 1; end if self.thistele%2 == 0 then i = self.thistele - 1; end if i > #_teleporters) --Abort teleport if unpaired then self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0 break end --]] --Below code is sequential teleport i = self.thistele + 1; if (i > #_teleporters) -- Kiosk keyboards suck. then i = 1; end for oactor in MovableMan.Actors do if (oactor.Pos.X >= _teleporters[i].Pos.X - 24) and (oactor.Pos.X <= _teleporters[i].Pos.X + 24) and (oactor.Pos.Y >= _teleporters[i].Pos.Y - 25) and (oactor.Pos.Y <= _teleporters[i].Pos.Y + 25) then oactor:GibThis(); _teleporters[i].teledelaytimer:Reset(); -- Needed _teleporters[i].teleactivate.Lifetime = 1; _teleporters[i].teleactivated = 0 end end actor:FlashWhite(1000); actor.Pos = _teleporters[i].Pos self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0 end end end end if self.teledelaytimer:IsPastSimMS(3000) -- Sanity Check. then self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0 end end end EDITEDIT: It seems to be giving an error on the last line of your code, mail2345. self.teleactivated = 0 It says that its a "nil" value.
|
Sat Apr 25, 2009 1:16 am |
|
|
Lord Tim
Joined: Fri Apr 27, 2007 4:55 pm Posts: 1178 Location: America!
|
Re: Lua based map objects, help! (BW related)
It is probably actually breaking the line before. Try: Code: if self.teledelaytimer:IsPastSimMS(3000) and self.teleactivate -- Sanity Check. then self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0 end
|
Sat Apr 25, 2009 1:43 am |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Lua based map objects, help! (BW related)
Found the issue. Turns out that the teleactivate check code forgot to check if it was also 0. Here is the should be fixed code. Code: function Create(self) if (_teleporters == nil) then _teleporters = {self} else table.insert(_teleporters,self) end self.teledelaytimer = Timer(); self.teleactivate = nil; self.thistele = #_teleporters; end
function Destroy(self) table.remove(_teleporters,self) end
function Update(self) if(#_teleporters > 1) then for actor in MovableMan.Actors do if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0)then if not self.teleactivated or self.teleactivated == 0 then self.teleactivate = CreateAEmitter("Teleport Activation"); self.teleactivate.Lifetime = 2000; self.teleactivate.Pos = self.Pos; self.teleactivate:EnableEmission(true); MovableMan:AddParticle(self.teleactivate); self.teledelaytimer:Reset(); self.teleactivated = 1 else if self.teledelaytimer:IsPastSimMS(2000)then --TELEPORTATION HAPPENS HERE local i = #_teleporters --Failsafe. -- The below commented code has random teleport. --[[ i = math.random(1,#_teleporters) while i == self.thistele do i = math.random(1,#_teleporters) end --]] --Below code is pair teleport --[[ if self.thistele%2 == 1 then i = self.thistele + 1; end if self.thistele%2 == 0 then i = self.thistele - 1; end if i > #_teleporters) --Abort teleport if unpaired then self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0 break end --]] --Below code is sequential teleport i = self.thistele + 1; if (i > #_teleporters) -- Kiosk keyboards suck. then i = 1; end for oactor in MovableMan.Actors do if (oactor.Pos.X >= _teleporters[i].Pos.X - 24) and (oactor.Pos.X <= _teleporters[i].Pos.X + 24) and (oactor.Pos.Y >= _teleporters[i].Pos.Y - 25) and (oactor.Pos.Y <= _teleporters[i].Pos.Y + 25) then oactor:GibThis(); _teleporters[i].teledelaytimer:Reset(); -- Needed _teleporters[i].teleactivate.Lifetime = 1; _teleporters[i].teleactivated = 0 end end actor:FlashWhite(1000); actor.Pos = _teleporters[i].Pos self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0 end end end end if self.teledelaytimer:IsPastSimMS(3000) and self.teleactivate -- Sanity Check. then self.teledelaytimer:Reset(); self.teleactivate.Lifetime = 1; self.teleactivated = 0; end end end
|
Sat Apr 25, 2009 4:49 am |
|
|
numgun
Joined: Sat Jan 13, 2007 11:04 pm Posts: 2932
|
Re: Lua based map objects, help! (BW related)
YES, YES! YES!!!1 The teleporters finally work like they should. Telefragging works like a charm and the effects flow like they should. Is there a way to attach a sound effect to play when you teleport? Also behold: The complete list of the areas that I have right now. The bunker building and the zerograv dont work, but thats something that Data needs to do in order them to work. I've re-tested the maps and removed/added some things to them so now they work smoothly and have complete sets of everything needed. I'm gonna also make a portable reconstructor (respawn actor anew once) as a buyable bomb thing.
|
Sat Apr 25, 2009 1:08 pm |
|
|
Lord Tim
Joined: Fri Apr 27, 2007 4:55 pm Posts: 1178 Location: America!
|
Re: Lua based map objects, help! (BW related)
AudioMan:PlaySound(nameofsoundthatwasalreadyloaded)
Data might need to change a bit of this so that it is usable from the Lua side (i.e. Allow us to use a string to specifiy the name of the sound). You might be able to use PresetMan:GetPreset("soundname") and pass that to PlaySound, but I forget if that works or not. You also have to create the sound in a .ini beforehand. See: Sounds.ini
|
Sat Apr 25, 2009 4:09 pm |
|
|
numgun
Joined: Sat Jan 13, 2007 11:04 pm Posts: 2932
|
Re: Lua based map objects, help! (BW related)
I just found something interesting: Code: AudioMan:PlayMusic("Base.rte/Music/dBSoundworks/ccambient4.ogg", 0, -1); It was in one mission script so I think I'll be able to skip the preloaded sound thing. Now I'm thinking here... Theres an assault rifle that has an underslung grenade launcher. That brings me to the next challenge: How would one be able to fire that grenade? After a plenty of FPS games I must say a seperate button for secondary firemode is the best and quickest method of making it work for the player. Another style would be "change ammo/function" style switch. In deus ex you had a machinegun that would need switching ammo in order to make the grenade launcher work. For that case it was cumbersome, but for a grenade launcher with different types of grenades like anti-infantry, EMP and such is ideal. Either of those function will require a new key bind, since I see no other way of it working (Except if an option could be added to the pie menu for the latter system.). So yeah: Is "secondary firemode/Switch ammo or function" even possible to do with Lua?
|
Sat Apr 25, 2009 5:08 pm |
|
|
Foa
Data Realms Elite
Joined: Wed Sep 05, 2007 4:14 am Posts: 3966 Location: Canadida
|
Re: Lua based map objects, help! (BW related)
Erm, how about an elevator, or escalator?
Some troopers are too encumbered to do any flying, and it'd make for a great [Escort Mode] Elevator. ( The escorted thing can't fly and has to go through many elevator towers, too bad that they are under a bad company's control! )
|
Sat Apr 25, 2009 5:43 pm |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Lua based map objects, help! (BW related)
Not sure if it's the optimal solution, but you can have the gun fire TDExplosives that quickly self destruct.
The lua then checks what mode the gun is on, and spawns the correct bullet/grenade.
Key access works, see the portal map(robolee's).
Not sure about the ammo part.
|
Sat Apr 25, 2009 6:48 pm |
|
|
numgun
Joined: Sat Jan 13, 2007 11:04 pm Posts: 2932
|
Re: Lua based map objects, help! (BW related)
Couple problems: 1. The "Ready" effect needs to be moved up, whats the right statement for that? Below is code where I tried something that failed. You can also seen in the picture on the greenish module there is a white text that says "Ready". That needs to be moved up by like 15 or so pixels. 2. PlaySound statement fails to work. Below picture of what it does when I try to use the module. It hits the part where its supposed to play the sound. 3. The "ready" effect doesnt go away after the module is used. Am I doing this code right? It seems to be adding more than one particles since the module started to lag CC alot. How to fix this? Code: function Create(self) x = self; regenchargetimer = Timer() regencharge = 15000 --10 sec recharge per healing end
function Destroy(self)
end
function Update(self) --Check if timer has passed and activates an effect to show the module is ready to use. if (regenchargetimer:IsPastSimMS(regencharge)) then self.readyfx = CreateAEmitter("Module Ready Signal") self.readyfx.Pos = self.Pos-- + (self.Pos.Y + 15) MovableMan:AddParticle(self.readyfx); end --First checks whether an actor or an item is within the box and then heals them. --NOTE: This wont heal busted limbs or wounds. Only the health count. Gibbing may be imminent even if the player got charged to 100 hp. for actor in MovableMan.Actors do if (regenchargetimer:IsPastSimMS(regencharge)) and (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.Health < 100) then actor:FlashWhite(500); AudioMan:PlaySound("Regen Module Sound"); actor.Health = 200; regenchargetimer:Reset() self.readyfx.Lifetime = 1 end end end
|
Sat Apr 25, 2009 11:43 pm |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Lua based map objects, help! (BW related)
I don't know about the play sound, but the ready thing is broken because it spawns over and over. Just add a variable to check if it already spawned. Code: function Create(self) x = self; regenchargetimer = Timer() regencharge = 15000 --10 sec recharge per healing self.ready = false; end
function Destroy(self) self.readyfx.Lifetime = 1 end
function Update(self) --Check if timer has passed and activates an effect to show the module is ready to use. if (regenchargetimer:IsPastSimMS(regencharge)) and self.ready == false then self.readyfx = CreateAEmitter("Module Ready Signal") self.readyfx.Pos = self.Pos-- + (self.Pos.Y + 15) MovableMan:AddParticle(self.readyfx); self.ready = true; end --First checks whether an actor or an item is within the box and then heals them. --NOTE: This wont heal busted limbs or wounds. Only the health count. Gibbing may be imminent even if the player got charged to 100 hp. for actor in MovableMan.Actors do if (regenchargetimer:IsPastSimMS(regencharge)) and (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.Health < 100) then actor:FlashWhite(500); self.ready = false AudioMan:PlaySound("Regen Module Sound"); actor.Health = 200; regenchargetimer:Reset() self.readyfx.Lifetime = 1 end end end I would guess that you need to add sound looping values.
|
Sun Apr 26, 2009 1:05 am |
|
|
|
Who is online |
Users browsing this forum: No registered users |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|