Jump to content

Kyun

Member
  • Posts

    144
  • Joined

  • Last visited

Everything posted by Kyun

  1. Hehe that's the first thing I looked at, although I didn't found setHurtMod in the documentation, so I think it wont work
  2. Hi, I modified a few stuff quickly to make it work with the current game (build 21). With Thuztor's permission here's the link : check gon's post at the bottom for an up to date, free of bug version. Current bug : - drawing the same shape with a different color will result in all idnetical shapes to share the same color (the last one used). So all squares are of the same color, all crosses are of (another) same color, etc ... If someone find out why (all the objects, say crosses, share the same sprite so this may explain that), please keep us informed . New version with minimal changes (no more bugs that I can see), paths are relative to the mod directory so Linux & Mac should be fine. If it doesn't work tell us. Credits to original devs : Thuztor, Peanuts, RobertJohnson.
  3. You were right, the OnPlayerMove trick did it. I can check my traps until I find (or don't) a trap on the square I am. I now die if I walk on one of my traps. (setHealth doesn't change my health, I think we'd need to make the object behave as a weapon swing) Thanks you for spotting the syntax error ... Although I still don't understand why I can't call some methods. Some sprites need changing according to their object status, I also planned to make bloody spikes once a zombie stepped on it, with durability etc ... but since I can't do anything else than kill the zombie straight, it will wait. I think it answers the OP (although not at best) on how to damage (kill) zombies with spikes (and the player). Use Events.OnObjectCollide and/or Event.OnPlayerMove to check if a zombie/player collide with one of your traps. Then do the work.
  4. Thanks you for your answer. Yes that's exactly object tried T call nill in NULL. Here's the function associated with a collision trigger so you can see what I'm doing : function Trap.SpikeTrapDmg(character, object) print("collision with " .. character:toString() .. " and " .. object:toString()); if object:getModData()['isTrap'] == 'true' and object:getModData()['trapId'] == "SpikeTrap" then local charstr = character:toString(); local str = "zombie.characters.IsoZombie"; local pstr = "zombie.characters.IsoGameCharacter "; -- zed if charstr:sub(1, str:len()) == str then --print(character:getHealth()); --character:setHealth(0); --if character:getHealth() == 0 then --character:setOnFloor(true); character:say("HAAAAA"); character:Kill(nil); -- getSpecificPlayer does not increase kill count --local weapon_effect = HandWeapon.new("Base", "Hammer", "Weapon", "Hammer"); --character:Hit(weapon_effect, getSpecificPlayer(0), 0,0,0); getSpecificPlayer(0):setZombieKills(getSpecificPlayer(0):getZombieKills() + 1); -- what happens is 2 zombies die at the same time ? need a lock Trap.destroyed(object); --end --- player does not trigger collision like zeds ? elseif charstr:sub(1, pstr:len()) == pstr then print("collision perso"); character:Say("Collision !"); --print("with player"); end endendEvents.OnObjectCollide.Add(Trap.SpikeTrapDmg);character:say("HAAAAA"); character:Hit(...) Don't work but Kill does. I have the same problem with destroying the trap (to make a sound like with a hammer, a hit fails, but the remove of the object works, and I use the playsound(breakdoor) ...). The first print (who collide with what) does not appear when it's me walking on the trap (it doesn't block all the square and i can go through it). The way I store stuff when creating any trap, in the parent file Trap.lua (each trap derives it) : function Trap:create(x, y, z, north, sprite) local cell = getWorld():getCell(); self.sq = cell:getGridSquare(x, y, z); self.javaObject = IsoThumpable.new(cell, self.sq, sprite, north, self); buildUtil.setInfo(self.javaObject, self); buildUtil.consumeMaterial(self); self.javaObject:setMaxHealth(self:getHealth()); self.javaObject:setBreakSound("breakdoor"); self.sq:AddSpecialObject(self.javaObject); if self.javaObject:getModData()["trapId"] == "SpikeTrap" then self.javaObject:getModData()['id'] = #trapping.spikeTrapsList + 1; table.insert(trapping.spikeTrapsList, self.javaObject); else self.javaObject:getModData()['id'] = #trapping.trapsList + 1; table.insert(trapping.trapsList, self.javaObject); endendAnd trapping.trapsList and spikeTrapList are in a trapping.lua file (used to load textures, loading on save load etc) : trapping = {};trapping.trapsList = {};trapping.spikeTrapsList = {};One more question : I remove the IsoThumpable trap using : local square = trap:getSquare();square:RemoveTileObject(trap);And not the method from the super class : ISBuildingObject.removeFromGround(square);Since the super look through all objects and maybe it can remove something else ? (on top of being slower ?) Well for now it kills zombies, produces a breakdoor sound, and an attract zombie sound of radius 10. Id's like to do small damages instead - but the collision trigger 100 times per second - and kill myself walking on it too.
  5. Hello fellow survivors, this is my first post and I seek your knowledge ! I bought Project Zomboid two days ago after playing the demo (awesome game btw) and went into modding for the first time ! So my 4 questions are related to this topic since I went with the same idea (I started from scratch since I didn't know lua ... I still don't ). I have somewhat managed to create traps (and have them properly reloaded after a save reload ...), submenu and stuff and to detect collisions with zombies (using Events.OnObjectCollide : character, object) checking for my IsoThumpable object (a trap). However : 1 : It seems only zombies are detected (character argument), never the player; is it expected behaviour ? Note that both zombies and player can pass through. 2 : The zombie class inherit from the more general character class and could use the method say(string) inherited from zombie.characters.IsoGameCharacterbut it seems zombies can't talk (nil table or something like that). It's the same with some other methods (splatBlood ...). 3 : Most important question : character.getHealth() returns 0 when used on a zombie (he's dead, somewhat logical), so how can my trap do damage to something that is dead ? Ok the collision is detected multiple times (100 ?) in a second interval, so the zombie health quickly drops to 0. Although it doesn't kill it, I found a solution using Kill(player) when health reach 0. Funny thing the collision still trigger for a while after the zombie's death 4 : to remember deployed traps, i use a table. However to refresh the sprite after save load i use Events.OnIsoThumpableLoad while the table keeps the IsoThumpable object found themselves, checking if id already exists (not a save load case). On many forums modders use Events.LoadGridsquare and a table with coordinates to detect an already existing Object in this table. But my traps are never found at the same place (by a few pixels ...) when doing so (i move far away and come back, 2 traps in the table ...), which result in a table linearly growing in size . Is the png sprite too small to cover a square and therefor move within the square between reloads? And what's the height of the png ? My traps are huge, like walls, they're to kill elephants! It's stretched all the way up to the roof. 4bis : To delete a trap from the table after removing it from the ground, I use table.remove(mytable, mykey), mykey in this case is just an integer since i store only objects as value. I read on some lua forums that it's not good and should use mytable[mykey] = nil. But the size of the map does not change doing so, or does it ? maybe #mytable is the number of elements, but the size of the value associated to "mykey" is 0 (since it's nil) so the table memory size is lower ? 5 : Am I going the wrong way ? Thank you for any input you may have and all the tutorials I found ! PS : i'm on build 21, the "iwillbackupmysave" branch.
×
×
  • Create New...