• DarkRP Entity Problem
    7 replies, posted
Hi, I've made an ent for DarkRP, and it was working fine, but suddenly it started giving me this error: [CODE] ERROR: GAMEMODE:'PlayerSay' Failed: DarkRP\gamemode\main.lua:1129: Tried to use a NULL entity! Error: hook->PlayerSay returned a non-string! [/CODE] The line number points to: item:SetPos(tr.HitPos) however 1128: item:SetNWEntity("owning_ent", ply) works fine??? This makes NO sense to me, and I reverted all changes to the entity itself since It started happening, but the error persists. This is the line in AddEntities.lua: [CODE]AddEntity("Marijuana Plant", "marijuana_plant", "models/props/cs_office/plant01.mdl", 100, 2, "/buymarijuanaplant")[/CODE] The init.lua for the entity itself is as follows: [lua]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self:SetModel("models/props/cs_office/plant01.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.sparkling = false self.damage = 100 timer.Simple(30, self.MakeBag, self) end function WiltEffect() Tbl[1] = Tbl[1] - Tbl2[1] Tbl[2] = Tbl[2] - Tbl2[2] Tbl[3] = Tbl[3] - Tbl2[3] Tbl[4] = Tbl[4] - Tbl2[4] DieTime = DieTime - 1 self:SetColor(Tbl[1], Tbl[2], Tbl[3], Tbl[4]) if (DieTime == 0) then Notify(ent:GetNWEntity("owning_ent"), 1, 4, "Your marijuana plant has died!") ent:Remove() end end function ENT:BeginDying() Notify(self:GetNWEntity("owning_ent"), 1, 4, "Your marijuana plant is dying!") self.IsDying = true DieTime = math.random(20, 50) Tbl = { self:GetColor() } Tbl2 = { Tbl[1] / DieTime, Tbl[2] / DieTime, Tbl[3] / DieTime, Tbl[4] / DieTime } end function MorePot(ent) if ValidEntity(ent) then ent.sparkling = true timer.Simple(3, ent.MakeBag, ent) end end function ENT:MakeBag() if not ValidEntity(self) then return end if self.IsDying then return end if self:IsOnFire() then return end local OutPos = self:GetPos() if math.random(1, 36) == 8 then self:BeginDying() end local ply = self:GetNWEntity("owning_ent") local marijuanaBag = ents.Create("durgz_weed") marijuanaBag:SetModel("/models/drugz_mod/katharsmodels/contraband/zak_wiet/zak_wiet.mdl") marijuanaBag:SetPos(Vector(OutPos.x, OutPos.y+15, OutPos.z+5)) marijuanaBag.ShareGravGun = true marijuanaBag.nodupe = true marijuanaBag:Spawn() self.sparkling = false timer.Simple(math.random(75, 250), MorePot, self) end function ENT:OnTakeDamage(dmg) if self.IsDying then return end self.damage = self.damage - dmg:GetDamage() if self.damage <= 0 then self:BeginDying() end end ENT.NextThink = 0 function ENT:Think() if !(CurTime() > self.NextThink) then return end if self.sparkling then local effectdata = EffectData() effectdata:SetOrigin(self:GetPos()) effectdata:SetMagnitude(1) effectdata:SetScale(1) effectdata:SetRadius(2) util.Effect("Sparks", effectdata) end if self:IsOnFire() and not self.IsDying then self.BeginDying() end if self.IsDying then WiltEffect() end self.NextThink = CurTime() + 1 end[/lua]
Any help at all? I've tried reinstalling darkRP, and redoing the AddEntity() line. But it still gives me an error that PlayerSay failed.
You can't expect us to debug your whole script for you, that's something you'll have to do yourself. Right now it's saying you're using a NULL entity, well why don't you go and find out which entity is NULL? Once you know which it is finding out why will be easy. My guess is that your entity has errors in it which stops it from loading, so use lua_reloadents ingame to reload all entities and look for errors. Errors aren't that hard to read.
[QUOTE=Crazy Quebec;18388011]My guess is that your entity has errors in it which stops it from loading, so use lua_reloadents ingame to reload all entities and look for errors. Errors aren't that hard to read.[/QUOTE] Thank you, I'll try this. EDIT: Yes, that resolved the issue, It said: entities/marijuana_plant/init.lua:52: function arguments expected near 'then' Folder = entities/marijuana_plant Couldn't register Scripted Entity marijuana_plant - the Type field is empty! I fixed the error on line 52 and can now spawn the plant. [editline]10:45PM[/editline] Now another problem arises: When this function is called: [lua] function DoNothing() local wat = nil end function WiltEffect(ent, time) local Tbl = { ent:GetColor() } local Xinc = Tbl[1] / time local Yinc = Tbl[2] / time local Zinc = Tbl[3] / time local AlphInc = Tbl[4] / time for i = 1, time do Tbl[1] = Tbl[1] - Xinc Tbl[2] = Tbl[2] - Yinc Tbl[3] = Tbl[3] - Zinc Tbl[4] = Tbl[4] - AlphInc ent:SetColor(Tbl[1], Tbl[2], Tbl[3], Tbl[4]) timer.Simple(1, DoNothing) end Notify(ent:GetNWEntity("owning_ent"), 1, 4, "Your marijuana plant has died!") ent:Remove() end[/lua] either it happens in a matter of milliseconds, or it doesn't do the for loop at all. When I hit the plant to dying, it just dissapears and doesn't darken a little every second like I want it to. I used a timer.Simple() because thats the easiest way I know to delay the script. This is the final bug in the SENT and I'm really looking forward to getting it onto our server. lua_reloadents doesn't give any errors for the SENT.
timer.Simple means that in 1 second DoNothing will be executed, it doesn't delay it in that sense. You could use a bunch of embeded timers calling one another but one of the simplest ways to do it is to use a think hook. [lua]ENT.NextThink = 0 --Initializing the variable function ENT:Think() if !(Curtime() > self.NextThink) then return end -- Execution ends here unless the current time is higher then NextThink self.NextThink = CurTime() + 3 --The next execution will be in 3 seconds print("Hey there!") end[/lua] This prints "Hey there!" every 3 seconds.
`When I use: if !(CurTime() > self.NextThink) then return end I get the following error: entities/marijuana_plant/init.lua:77: attempt to compare function with number Should also be noted that the sparks effect has stopped working for some reason. I'll update my first post with the new script.
[QUOTE=IAMYourReason;18396417]`When I use: if !(CurTime() > self.NextThink) then return end I get the following error: entities/marijuana_plant/init.lua:77: attempt to compare function with number Should also be noted that the sparks effect has stopped working for some reason. I'll update my first post with the new script.[/QUOTE] Are you using an entity base? Because either it has defined ENT.NextThink as a function or you have. Try another name and see what it does? :smile: Also are you sure your effect being broken doesn't have to do with it being placed after an error in the code? :v:
Okay, everything is fixed, I did some research on the wiki for entity.nextthink() and It gave me the code. Thank you for your help, I now have to go to bed (its like 3 AM here)??? Sparks works again, and the effect renders (Using a Think hook btw thanks for that idea)
Sorry, you need to Log In to post a reply to this thread.