-
Posts
203 -
Joined
-
Last visited
Content Type
Blogs
Forums
Store
Gallery
Videos
Posts posted by burgelkat
-
-
function Script:Start() self.close=false self.conservation2=false end -----------------------Conservation-------------------------- function Script:StartConservation()--in System:Print("Conservation") self:ConservationPart1() end function Script:ConservationPart1() Talkingpanel=gui System:Print("TextShow") local Talkingpanel={} local scale = 1 --GUI local gui = GUI:Create(context) Talkingpanel.gui=gui Talkingpanel.context = context Talkingpanel = Widget:Panel(gui:GetBase():GetClientSize().x/2+150,gui:GetBase():GetClientSize().y/2-300,500,600,gui:GetBase()) Talkingpanel:SetAlignment(0,0,0,0) Talkingpanel.Talkingpanel=Talkingpanel Talkingpanel=Talkingpanel local widget widget = Widget:Tabber(indent,indent,Talkingpanel:GetClientSize().x-indent*2,Talkingpanel:GetClientSize().y-indent*2,Talkingpanel) widget:AddItem("Name of Person",true) x=30 y=60 Talkingpanel:SetObject("backgroundcolor",Vec4(0.15,0.15,0.15,1)) Talkingpanel.tabber = widget local indent = 12 Talkingpanel = Widget:Panel(indent,indent,widget:GetClientSize().x-indent*2,widget:GetClientSize().y-indent*2-30,widget) Talkingpanel = Widget:TextArea(x,y,Talkingpanel:GetClientSize().x-indent*2-50,Talkingpanel:GetClientSize().y-indent*2-300,Talkingpanel) --------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------Dialog 1----------------------------------------------------------------------------- Talkingpanel:SetText(" NPC Text 1 ") Talkingpanel:SetBool("border",true) Talkingpanel.panel={} Talkingpanel.panel.general=panel Talkingpanel.btnClose = Widget:Button("Close",widget:GetClientSize().x-72-indent,widget:GetClientSize().y-28-5,72,28,widget) Talkingpanel.btnClose:SetStyle(BUTTON_CANCEL) ------------------------------------------------------------------------------------------------------------------ --Talkingpanel.btnClose = Widget:Button("Close",widget:GetClientSize().x-450-indent,widget:GetClientSize().y-250,100,28,widget) --Talkingpanel.btnClose:SetStyle(BUTTON_CANCEL) Talkingpanel.btnConservation2 = Widget:Button("Answer 1",widget:GetClientSize().x-450-indent,widget:GetClientSize().y-280,160,28,widget) Talkingpanel.btnConservation2:SetStyle(BUTTON_CANCEL) Talkingpanel.btnConservation3 = Widget:Button("Answer 2",widget:GetClientSize().x-450-indent,widget:GetClientSize().y-280,300,28,widget) Talkingpanel.btnConservation3:SetStyle(BUTTON_CANCEL) ----------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------------------------- Talkingpanel.btnConservation3:Hide() local y=20 local sep=40 while true do world:Render() Time:Update() Time:Resume() window:ShowMouse() if window:Closed() then return end ---------------------------------------------------------------------------------------------- while EventQueue:Peek() do local event = EventQueue:Wait() if event.id == Event.WidgetAction then ---------------------------------------------------------- if event.source == Talkingpanel.btnClose then --self:ProcessEvent(Event(Event.WidgetAction,Talkingpanel.btnClose)) System:Print("WidgetAction1") self.component:CallOutputs("Output1") Talkingpanel.btnClose:Hide() window:FlushMouse() window:FlushKeys() window:HideMouse() window:SetMousePosition(window:GetWidth()/2,window:GetHeight()/2) gui:Hide() widget:Hide() return elseif event.source == Talkingpanel.btnConservation2 then --self:ProcessEvent(Event(Event.WidgetAction,Talkingpanel.btnConservation2)) System:Print("WidgetAction2") Talkingpanel:SetText("NPC Text 2") Talkingpanel.btnConservation2:Hide() Talkingpanel.btnConservation3:Show() elseif event.source == Talkingpanel.btnConservation3 then System:Print("WidgetAction3") self.component:CallOutputs("EndConservation3") Talkingpanel.btnConservation3:Hide() end end end context:Sync() end end
Mybe someone can use it for NPC conversations
- 1
-
ok, solved it.
In the player script I have to make a reference to the weapon index in order to trigger the function.
self.weapons[self.currentweaponindex]:becomewater()
-
ah ok got it.. thanks .. i try .. and post again if it function. many thanks
-
thanks for your answer. i got the first part.
but at the "DoSomething" it crashs to desktop without error
-
Hallo,
i hope someone can explain this to me.
i build a vwep praefab (like autogun)
this script function and the bucket is show
in the Start function i have this code.
if i take the bucket, the child is now hidden.
function Script:Start() local child = self.entity:FindChild("WaterforBucket") child:Hide()
the problem now is, if i would show it again, i got an error.
this is the code for showing the child
function Script:becomewater()--in self.becomewater=true local child = self.entity:FindChild("WaterforBucket") if child:Hidden() then child:Show() end end
the child is now nil. (Script Error attempt to index local "child" (a nil value)
why now the child is not found?
can someone explain and how i can fix it?
-
thanks for the replay .. i think i should explain a little better.
this ist the working script, but only with one button
function Script:Start() self.close=false self.conservation2=false end -----------------------Conservation-------------------------- function Script:StartConservation()--in System:Print("Conservation") self:Conservation1() end function Script:Conservation1() Talkingpanel=gui System:Print("TextShow") local Talkingpanel={} local scale = 1 --GUI local gui = GUI:Create(context) Talkingpanel.gui=gui Talkingpanel.context = context Talkingpanel = Widget:Panel(gui:GetBase():GetClientSize().x/2+150,gui:GetBase():GetClientSize().y/2-300,500,600,gui:GetBase()) Talkingpanel:SetAlignment(0,0,0,0) Talkingpanel.Talkingpanel=Talkingpanel Talkingpanel=Talkingpanel local widget widget = Widget:Tabber(indent,indent,Talkingpanel:GetClientSize().x-indent*2,Talkingpanel:GetClientSize().y-indent*2,Talkingpanel) widget:AddItem("Old Man",true) x=30 y=60 Talkingpanel:SetObject("backgroundcolor",Vec4(0.15,0.15,0.15,1)) Talkingpanel.tabber = widget local indent = 12 Talkingpanel = Widget:Panel(indent,indent,widget:GetClientSize().x-indent*2,widget:GetClientSize().y-indent*2-30,widget) Talkingpanel = Widget:TextArea(x,y,Talkingpanel:GetClientSize().x-indent*2-50,Talkingpanel:GetClientSize().y-indent*2-300,Talkingpanel) --------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------Dialog 1----------------------------------------------------------------------------- Talkingpanel:SetText("Mhm? What do you want from me?") Talkingpanel:SetBool("border",true) Talkingpanel.panel={} Talkingpanel.panel.general=panel --Talkingpanel.btnClose = Widget:Button("Close",widget:GetClientSize().x-72-indent,widget:GetClientSize().y-28-5,72,28,widget) --Talkingpanel.btnClose:SetStyle(BUTTON_CANCEL) ------------------------------------------------------------------------------------------------------------------ local y=20 local sep=40 while true do Time:Update() window:ShowMouse() if window:Closed() then return end --if window:KeyHit(Key.Escape) then return end ---------------------------------------------------------------------------------------------- while EventQueue:Peek() do local event = EventQueue:Wait() if event.id == Event.WidgetAction then System:Print("Conservation2") self.conservation2=true return end end context:Sync() end end
so with one button its no problem.
i really try now to understand how it function with more then one button . becaus this event is for all buttons in the script.
so i search some posts and look into menu.lua to understand. but if i try to do the same, the button have no reacton
this is the code ( i cleaned it a little)
function Script:Start() self.close=false self.conservation2=false end -----------------------Conservation-------------------------- function Script:StartConservation()--in self:Conservation1() System:Print("Conservation") --self.component:CallOutputs("Conservation") end function Script:Conservation1() local Talkingpanel={} local scale = 1 --GUI local gui = GUI:Create(context) --Talkingpanel.context = context Talkingpanel = Widget:Panel(gui:GetBase():GetClientSize().x/2+150,gui:GetBase():GetClientSize().y/2-300,500,600,gui:GetBase()) Talkingpanel:SetAlignment(0,0,0,0) Talkingpanel.Talkingpanel=Talkingpanel Talkingpanel=Talkingpanel local widget widget = Widget:Tabber(indent,indent,Talkingpanel:GetClientSize().x-indent*2,Talkingpanel:GetClientSize().y-indent*2,Talkingpanel) widget:AddItem("Old Man",true) x=30 y=60 Talkingpanel:SetObject("backgroundcolor",Vec4(0.15,0.15,0.15,1)) Talkingpanel.tabber = widget local indent = 12 Talkingpanel = Widget:Panel(indent,indent,widget:GetClientSize().x-indent*2,widget:GetClientSize().y-indent*2-30,widget) Talkingpanel = Widget:TextArea(x,y,Talkingpanel:GetClientSize().x-indent*2-50,Talkingpanel:GetClientSize().y-indent*2-300,Talkingpanel) --------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------Dialog 1----------------------------------------------------------------------------- Talkingpanel:SetText("Mhm? What do you want from me?") Talkingpanel:SetBool("border",true) Talkingpanel.panel={} Talkingpanel.panel.general=panel Talkingpanel.btnClose = Widget:Button("Close",widget:GetClientSize().x-72-indent,widget:GetClientSize().y-28-5,72,28,widget) Talkingpanel.btnClose:SetStyle(BUTTON_CANCEL) ------------------------------------------------------------------------------------------------------------------ Talkingpanel.btnConservation1 = Widget:Button("Who am i?",widget:GetClientSize().x-450-indent,widget:GetClientSize().y-250,72,28,widget) Talkingpanel.btnConservation1:SetStyle(BUTTON_CANCEL) ------------------------------------------------------------------------------------------------------------------ local y=20 local sep=40 ----------------------------------------------------------------------------------------------------- while true do Time:Update() window:ShowMouse() if window:Closed() then return end ----------------------------------------------------------------------------------------------------- function Talkingpanel:ProcessEvent(event) if event.id == Event.WidgetAction then if self.event.source == self.btnClose then self:ProcessEvent(Event(Event.WidgetAction,self.btnClose)) System:Print("WidgetAction") self.component:CallOutputs("LostAttention") Talkingpanel.btnClose:Hide() window:FlushMouse() window:FlushKeys() window:HideMouse() window:SetMousePosition(window:GetWidth()/2,window:GetHeight()/2) gui:Hide() widget:Hide() end end end function Talkingpanel:Update() if self.btnClose:GetText()=="Close" then self:ProcessEvent(Event(Event.WidgetAction,self.btnClose)) end while EventQueue:Peek() do self.event = EventQueue:Wait() if self:ProcessEvent(event)==false then return false end end return true end context:Sync() end end
the Widget show up with buttons but if i click on the button. nothing happens. I cleand this code to only one Event becaus if the Event Close
function, i think i understand and the other buttons will function too.
i hope really someone understand me and can help me here
-
-
Hallo,
I am experimenting with widgets. I don't know what I'm doing wrong here. A single button as described in the documentation works very well. But if I want to use more buttons, it doesn't respond. What am I doing wrong?
i hope someone can help
function Script:Start() self.close=false self.conservation2=false end -----------------------Conservation-------------------------- function Script:StartConservation()--in System:Print("Conservation") self.component:CallOutputs("Conservation") end function Script:Conservation1()--in local gamemenu={} gameMenu=gui System:Print("TextShow") local Talkingpanel={} local scale = 1 --GUI local gui = GUI:Create(context) -----------------------no need for this ------------------ --gui:Show() --gui:SetScale(scale) --gui:GetBase():SetScript("Scripts/GUI/Panel.lua") --gui:GetBase():SetObject("backgroundcolor",Vec4(0.2,0.2,0.2,1)) ------------------------------------------------------------ Talkingpanel.gui=gui Talkingpanel.context = context Talkingpanel = Widget:Panel(gui:GetBase():GetClientSize().x/2+150,gui:GetBase():GetClientSize().y/2-300,500,600,gui:GetBase()) Talkingpanel:SetAlignment(0,0,0,0) Talkingpanel.Talkingpanel=Talkingpanel Talkingpanel=Talkingpanel local widget widget = Widget:Tabber(indent,indent,Talkingpanel:GetClientSize().x-indent*2,Talkingpanel:GetClientSize().y-indent*2,Talkingpanel) widget:AddItem("Old Man",true) x=30 y=60 --Talkingpanel = Widget:TextArea(indent,indent,400,150,Talkingpanel) --Talkingpanel = Widget:TextArea(x,y,Talkingpanel:GetClientSize().x-indent*2-50,Talkingpanel:GetClientSize().y-indent*2-300,Talkingpanel) --Talkingpanel:SetText("Mhm? What do you want from me?") Talkingpanel:SetObject("backgroundcolor",Vec4(0.15,0.15,0.15,1)) Talkingpanel.tabber = widget local indent = 12 Talkingpanel = Widget:Panel(indent,indent,widget:GetClientSize().x-indent*2,widget:GetClientSize().y-indent*2-30,widget) Talkingpanel = Widget:TextArea(x,y,Talkingpanel:GetClientSize().x-indent*2-50,Talkingpanel:GetClientSize().y-indent*2-300,Talkingpanel) --------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------Dialog 1----------------------------------------------------------------------------- Talkingpanel:SetText("Mhm? What do you want from me?") Talkingpanel:SetBool("border",true) Talkingpanel.panel={} Talkingpanel.panel.general=panel Talkingpanel.closeoptions = Widget:Button("Close",widget:GetClientSize().x-72-indent,widget:GetClientSize().y-28-5,72,28,widget) Talkingpanel.closeoptions:SetStyle(BUTTON_CANCEL) ------------------------------------------------------------------------------------------------------------------ Talkingpanel.Conservation1 = Widget:Button("Who am i?",widget:GetClientSize().x-450-indent,widget:GetClientSize().y-250,72,28,widget) Talkingpanel.Conservation1:SetStyle(BUTTON_CANCEL) ------------------------------------------------------------------------------------------------------------------ local y=20 local sep=40 ----------------------------------------------------------------------------------------------------- while true do Time:Update() window:ShowMouse() if window:Closed() then return end --if window:KeyHit(Key.Escape) then return end ---------------------------------------------------------------------------------------------- function Talkingpanel:ProcessEvent(event) if event.id == Event.WidgetAction then if event.source == self.closeoptions then System:Print("WidgetAction") self.component:CallOutputs("Close") Talkingpanel.button:Hide() window:FlushMouse() window:FlushKeys() window:HideMouse() window:SetMousePosition(window:GetWidth()/2,window:GetHeight()/2) gui:Hide() widget:Hide() end end end function Talkingpanel:Update() if self.closeptions:GetText()=="Close" then self:ProcessEvent(Event(Event.WidgetAction,self.closeoptions)) end while EventQueue:Peek() do local event = EventQueue:Wait() if self:ProcessEvent(event)==false then return false end end return true end context:Sync() end end
-
Hi , Top down shooting Game I tried to create during the summer holidays. I wanted to introduce it to the next event, something like "Halloweeen Event" by Josh. At least my Light version. I called the project "Blue Max". Maybe someone still remembers the old game on the Atari 2600. A screenshot I had set on Discord. Light version because my programming skills are very limited and I am still learning and trying hard so there are still bugs in it . You could also "pimp it up". It based on Joshs Game "Astroid"
Other wise, I had the days also thought something like "International Karate" but with new Game Engine
-
if i remeber correct this was c++ if it is possible and someone translate it in lua (i am to bad) this was also a nice effect
-
it looks like I'm very creative today. Yeah, I have a welder. mhm .. ok .. and what now?
-
no not yet. But I think if you invest more time, you get a nice explosion. My explosion was only a quick version. I have to spend more time in this. maybe later
- 1
-
try this webside.. than make a sprite sheet with the explosion
- 1
-
yes thats the way it is so much fun to create spritesheets for this .. I do not know about you, but I play games now with completely different eyes. "oh, I could try that in leadwerks too .."
-
-
Hi,
Here is an effect to bring more life into the landscape. I used a sprite sheet with an emitter ..
- 5
-
Here the sprite sheet if someone will use it
thx josh will try your hints
- 1
- 1
-
ok looks with that nice. at the moment only single-shot looks good .. i have to build a spritesheet without a bullet shell
so thats my solution for the moment
-
ok something like this .. (its not perfekt)
https://www.dropbox.com/s/atjdn8xc7ef5os8/BehindEnemyLines 2018-03-16 09-19-46-90.avi?dl=0
-
mhm or the problem is because we create the sprite and hide it .. so the material on the sprite is set and run the spritesheet pictures in the backround .. if i now show the sprite and at this moment the 4th picture is displayed, then it looks bad
-
thats a good video .. but how can i control the pictures in a sprite sheet? the spritesheet shader like the "firepit" shader from shadmar starts random in the individual pictures of a sprite sheets. In the case of fire this is not a problem, with explosions or with Gun Effects it should begin however with the first picture. I have such a spritesheet (muzzleflash .. a bullet and smokes but it does not start on the first picture. And creating an effect with maybe 20 seperatly bictures is a bit exhausting (I hope you understand my english )
-
i read this post https://www.leadwerks.com/community/topic/9862-small-entities-fall-through-terrain/
buit if i use force i have to add a Mass so rey cast for this not work
-
Hi ,
i will share my solution for the Mortar.
Mortar = a Pivot put there this script in (MortarTracking.lua)
import "Scripts/Functions/ReleaseTableObjects.lua" import "Scripts/Functions/GetEntityNeighbors.lua" Script.enabled=true--bool "Enabled" Script.trackingrange = 10 Script.tracking=false function Script:Enable()--in if self.enabled==false then self.enabled=true self.component:CallOutputs("Enable") end end function Script:Disable()--in if self.enabled then self.enabled=false self.component:CallOutputs("Disable") end end function Script:UpdatePhysics() if self.enabled then -- load entities within range (5000) of self.entity into "entities", only load entities that have scripts attached local entities = GetEntityNeighbors(self.entity,5000,true) local k,entity -- loop thrrough the result of "entities". k = key, entity = result for k,entity in pairs(entities) do -- only select entities with teamid == 1 ("good") if entity.script.teamid == 1 then -- and if the entity has at least 1 health remaining if entity.script.health>0 then local d = self.entity:GetDistance(entity) self.target = entity end local pos = self.entity:GetPosition() local targetpos = self.target:GetPosition() --if math.abs(targetpos.y-pos.y)<1.5 then if pos:xz():DistanceToPoint(targetpos:xz())<self.trackingrange then self.tracking=false else self.tracking=true end end end if self.tracking==true then self.entity:Point(self.target,2,Time:GetSpeed()*1.5); end end end
in Mortar Body = the Model put in the script (Mortar.lua)
import "Scripts/Functions/ReleaseTableObjects.lua" import "Scripts/Functions/GetEntityNeighbors.lua" Script.enabled=true--bool "Enabled" --Public Script.target = nil--enemy to shoot Script.teamid=3--choice "Team" "Neutral,Good,Bad" Script.range = 5000 Script.health=100 Script.projectilepath = "Prefabs/projectiles/MortarAmmo.pfb" Script.shoot1sound=""--path "File" "All Supported Files:ogg,wav;Waveform Audio File Format (*.wav):wav;Ogg Vorbis (*.ogg):ogg|Sound" Script.shoot2sound=""--path "File" "All Supported Files:ogg,wav;Waveform Audio File Format (*.wav):wav;Ogg Vorbis (*.ogg):ogg|Sound" Script.shoot3sound=""--path "File" "All Supported Files:ogg,wav;Waveform Audio File Format (*.wav):wav;Ogg Vorbis (*.ogg):ogg|Sound" --Private Script.lastfiretime=0 Script.mode = "idle" Script.lastsearchtime = 0 Script.searchfrequency = 500 Script.firefrequency = 4000 Script.Force1 = Vec3(0,1500,0) Script.Force2 = Vec3(0,2500,0) Script.Force3 = Vec3(0,3000,0) Script.Force4 = Vec3(0,3500,0) Script.range0 = 20 Script.range1 = 30 Script.range2 = 60 Script.range3 = 90 Script.range4 = 110 function Script:Start() --Load sounds self.sound = {} self.sound.shoot = {} if self.shoot1sound~="" then self.sound.shoot[1] = Sound:Load(self.shoot1sound) end if self.shoot2sound~="" then self.sound.shoot[2] = Sound:Load(self.shoot2sound) end if self.shoot3sound~="" then self.sound.shoot[3] = Sound:Load(self.shoot3sound) end self.projectile = Prefab:Load(self.projectilepath) if self.projectile~=nil then self.projectile:Hide() end self.Mortar = self.entity:FindChild("Mortar") --Add muzzleflash to gun self.muzzle = self.entity:FindChild("muzzle") if self.muzzle~=nil then local mtl=Material:Create() mtl:SetBlendMode(5) self.muzzle:SetMaterial(mtl) mtl:Release() self.muzzleflash = Sprite:Create() self.muzzleflash:SetSize(0.35,0.35) local pos=self.muzzle:GetPosition(true) self.muzzleflash:SetPosition(pos,true) self.muzzleflash:SetParent(self.muzzle,true) mtl = Material:Load("Materials/Effects/muzzleflash.mat") if mtl then self.muzzleflash:SetMaterial(mtl) mtl:Release() mtl=nil end local light = PointLight:Create() light:SetRange(5) light:SetColor(1,0.75,0) light:SetParent(self.muzzleflash,flash) if light.world:GetLightQuality()<2 then light:SetShadowMode(0) end self.muzzleflash:Hide() end end function Script:Release() if self.projectile~=nil then self.projectile:Release() self.projectile = nil end end function MortarSearchHook(entity,extra) if entity~=extra then if entity.script~=nil then if entity.script.teamid == 1 then if type(entity.script.health)=="number" then if entity.script.health>0 then local d = extra:GetDistance(entity) if d<extra.script.range then if extra.script.target~=nil then if extra.script:GetDistance(extra.script.target)>d then if extra.script:GetTargetVisible(entity.script) then extra.script.target = entity.script end end else if extra.script:GetTargetVisible(entity.script) then extra.script.target = entity.script end end end end end end end end end function Script:GetTargetVisible(target) if target==nil then target = self.target end if target==nil then return false end local pickinfo = PickInfo() local p0 = self.entity:GetAABB().center local p1 = target.entity:GetAABB().center local pickmode0 = self.entity:GetPickMode() local pickmode1 = target.entity:GetPickMode() self.entity:SetPickMode(0) target.entity:SetPickMode(0) local result = not self.entity.world:Pick(p0,p1,pickinfo,0,false,Collision.LineOfSight) self.entity:SetPickMode(pickmode0) target.entity:SetPickMode(pickmode1) return result end function Script:UpdateWorld() if self.enabled==true then if self.health>=0 then self.component:CallOutputs("Online") local currenttime = Time:GetCurrent() --Stop shooting if target is dead if self.target~=nil then if self.target.health<=0 then self.component:CallOutputs("Idle") self.target = nil end end --Search for target if self.enabled==true then if self.target==nil then if currenttime - self.lastsearchtime > self.searchfrequency then self.lastsearchtime = currenttime local pos = self.entity:GetPosition(true) local aabb = AABB(pos - Vec3(self.range), pos + Vec3(self.range)) self.entity.world:ForEachEntityInAABBDo(aabb,"MortarSearchHook",self.entity) end end end ---------------------deactivated because the Mortar should fire if vegetation hides you----------------- --Continuous visibility test --[[ if self.target~=nil then if currenttime - self.lastsearchtime > self.searchfrequency then self.lastsearchtime = currenttime if self:GetTargetVisible(self.target)==false then self.target = nil return end end end]] ---------------------------------------------------------------------------------------------------------- if self.target~=nil then ---------------------------no need for this (i think)--------------------------------------------------------------- --[[Motion tracking if self.Mortar~=nil then local p0 = self.Mortar:GetPosition(true) local p1 = self.target.entity:GetAABB().center local yplane = p1 - p0 yplane.y=0 self.Mortar:AlignToVector(yplane,1,0.1 / Time:GetSpeed(),0) end]] ---------------------------------------------------------------------------------------------------------- --Shoot if self.muzzle~=nil and self.projectile~=nil then if currenttime - self.lastfiretime > self.firefrequency then self.lastfiretime = currenttime local bullet = self.projectile:Instance() self.muzzleflash:Show() self.muzzleflash:EmitSound(self.sound.shoot[#self.sound.shoot]) self.muzzleflash:SetAngle(math.random(0,360)) self.muzzleflashtime=currenttime if bullet~=nil then bullet:Show() bullet:SetFriction(1000,1000) bullet:SetCollisionType(Collision.Projectile) bullet:SetPosition(self.muzzle:GetPosition(true),true) bullet:SetRotation(self.muzzle:GetRotation(true),true) targetpos = self.target.entity:GetPosition() pos1 = self.entity:GetPosition(true) --if math.abs(targetpos.y-pos1.y)<1.5 then -------------------------------------------------Fire Range--------------------------------------------------------------------- if pos1:xz():DistanceToPoint(targetpos:xz())<self.range1 then System:Print("1") bullet:AddForce(self.Force1) else if pos1:xz():DistanceToPoint(targetpos:xz())<self.range2 then System:Print("2") bullet:AddForce(self.Force2) else if pos1:xz():DistanceToPoint(targetpos:xz())<self.range3 then System:Print("3") bullet:AddForce(self.Force4) else if pos1:xz():DistanceToPoint(targetpos:xz())<self.range4 then System:Print("4") bullet:AddForce(self.Force4) else return 100000 end end end end -------------------------------------------------------------------------------------------------------------------------------- bullet:SetMass(0.4) if bullet.script~=nil then bullet.script.owner = self if type(bullet.script.Enable)=="function" then bullet.script:Enable() end bullet:Turn(Math:Random(-4,4),Math:Random(-4,4),0) end end end end end end if self.health<=0 then self.component:CallOutputs("Offline") end self:UpdateMuzzleFlash() end end function Script:UpdateMuzzleFlash() if self.muzzleflashtime then if Time:GetCurrent()-self.muzzleflashtime<30 then self.muzzleflash:Show() else self.muzzleflash:Hide() end end end function Script:Online()--in if self.enabled==false then self.component:CallOutputs("Online") self.enabled=true end end function Script:Offline()--in if self.enabled==true then self.component:CallOutputs("Offline") self.enabled=false end end
for the Ammo
search a model like my on http://www.cadnav.com/3d-models/model-42383.html
and put the script "MortarAmmo" in
Script.movespeed=1000 Script.pickradius=0 Script.damage=10 Script.lifetime=20000 Script.enabled=false--bool "Enabled" function Script:Start() self.sound={} self.sound.ricochet={} self.sound.ricochet[1]=Sound:Load("Sound/Weapons/Explosion.wav") self.sound.ricochet[2]=Sound:Load("Sound/Weapons/Explosion.wav") self.sound.ricochet[3]=Sound:Load("Sound/Weapons/Explosion.wav") self.starttime=Time:GetCurrent() self.emitter={} --Debris emitter - This will throw chunks off of walls and make it look like they are breaking self.emitter[0]=Emitter:Create() self.emitter[0]:SetCollisionType(Collision.Prop)--Enables particle bouncing self.emitter[0]:SetMaterial("Materials/Effects/smoke.mat") self.emitter[0]:SetEmissionVolume(0.05,0.05,0.05) self.emitter[0]:SetColor(0.1,0.1,0.1,1) self.emitter[0]:SetVelocity(5.5,15,5.5,1) self.emitter[0]:SetParticleCount(20) self.emitter[0]:SetReleaseQuantity(20) self.emitter[0]:SetMaxScale(0.9) self.emitter[0]:SetDuration(1500) self.emitter[0]:SetAcceleration(0,-12,0) self.emitter[0]:SetLoopMode(false) self.emitter[0]:Hide() --Smoke emitter - This will provide a soft dust effect around bullet impacts self.emitter[1]=Emitter:Create() self.emitter[1]:SetColor(1,1,1,0.25) self.emitter[1]:SetMaterial("Materials/Effects/smoke.mat") self.emitter[1]:SetEmissionVolume(0.1,0.1,0.1) self.emitter[1]:SetVelocity(0.3,0.3,0.3,1) self.emitter[1]:SetParticleCount(8) self.emitter[1]:SetReleaseQuantity(3) self.emitter[1]:SetMaxScale(15) self.emitter[1]:SetDuration(3800) self.emitter[1]:AddScaleControlPoint(0,0.5) self.emitter[1]:AddScaleControlPoint(1,1) self.emitter[1]:SetRotationSpeed(10) self.emitter[1]:SetLoopMode(false) self.emitter[1]:Hide() --Smoke emitter - This will provide a soft dust effect around bullet impacts self.emitter[2]=Emitter:Create() self.emitter[2]:SetColor(1,1,1,0.25) self.emitter[2]:SetMaterial("Prefabs/Effects/Explosion/explosion.mat") self.emitter[2]:SetEmissionVolume(0.1,0.1,0.1) self.emitter[2]:SetVelocity(0.3,0.3,0.3,1) self.emitter[2]:SetParticleCount(1) self.emitter[2]:SetReleaseQuantity(1) self.emitter[2]:SetMaxScale(25) self.emitter[2]:SetDuration(2500) self.emitter[2]:AddScaleControlPoint(0,0.5) self.emitter[2]:AddScaleControlPoint(1,1) self.emitter[2]:SetRotationSpeed(10) self.emitter[2]:SetLoopMode(false) self.emitter[2]:Hide() end function Script:Enable() if self.enabled==false then self.enabled=true end end function Script:FindScriptedParent(entity,func) while entity~=nil do if entity.script then if type(entity.script[func])=="function" then return entity end end entity = entity:GetParent() end return nil end function Script:UpdateWorld() if self.enabled==false then return end if self.entity:Hidden() then return end local pickinfo=PickInfo() local pos = self.entity:GetPosition(true) local targetpos = Transform:Point(0,0,self.movespeed/60.0 * Time:GetSpeed(),self.entity,nil) local result = self.entity.world:Pick(pos,targetpos,pickinfo,self.pickradius,true,Collision.Projectile) if result then local enemy = self:FindScriptedParent(pickinfo.entity,"Hurt") if enemy then if self.owner then --if self.owner.teamid==enemy.script.teamid then -- result=false --end end if result then if enemy.script.health>0 then enemy.script:Hurt(self.damage,self.owner) end end end if result then self:Explode() --Bullet mark decal local mtl local scale = 2 if enemy~=nil then mtl = Material:Load("Materials/Decals/wound.mat") scale = 0.1 else if pickinfo.surface~=nil then local pickedmaterial = pickinfo.surface:GetMaterial() if pickedmaterial~=nil then rendermode = pickedmaterial:GetDecalMode() end end mtl = Material:Load("Materials/Decals/BombCrater.mat") end local decal = Decal:Create(mtl) decal:AlignToVector(pickinfo.normal,2) decal:Turn(0,0,Math:Random(0,360)) decal:SetScript("Scripts/Objects/Effects/BulletMark.lua") if mtl~=nil then mtl:Release() end decal:SetPosition(pickinfo.position) decal:SetParent(pickinfo.entity) --Apply global scaling local mat = decal:GetMatrix() mat[0] = mat[0]:Normalize() * scale mat[1] = mat[1]:Normalize() * scale mat[2] = mat[2]:Normalize() * scale decal:SetMatrix(mat) decal:EmitSound(self.sound.ricochet[math.random(#self.sound.ricochet)],30) self.entity:Release() else self.entity:SetPosition(targetpos) end else self.entity:SetPosition(targetpos) end if Time:GetCurrent()-self.starttime>self.lifetime then self.entity:Release() end end function Script:Explode() self.entity:EmitSound(self.sound.ricochet[math.random(#self.sound.ricochet)],30) self.emitter[0]:Show() self.emitter[0]:SetPosition(self.entity:GetPosition(true)) self.emitter[0]:Reset() self.emitter[0]:Play() self.emitter[1]:Show() self.emitter[1]:Reset() self.emitter[1]:SetPosition(self.entity:GetPosition(true)) self.emitter[1]:Play() self.emitter[2]:Show() self.emitter[2]:Reset() self.emitter[2]:SetPosition(self.entity:GetPosition(true)) self.emitter[2]:Play() end function Script:Collision(entity, position, normal, speed) self:Explode() end
ok so far so good i hope you have fun.
at the moment i think the scripts can be better written... for sure the Ammo script
because it use the raycast to detect impact. i build in a collision line additional but this is not a perfect solution
because the decal works only on pick
ok changes from you are welcome in this post
- 2
-
How did. you import it? Maybe a dump question
Deforming terrain?
in General Discussion
Posted
Maybe you can build this in blender and use the result as model?