jesserocks3357 / darkrp

Automatically exported from code.google.com/p/darkrp
0 stars 1 forks source link

function DB.RetrieveFreeZombieSpawnPos() #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
function DB.RetrieveFreeZombieSpawnPos()
    local map = string.lower(game.GetMap())
    local r = false
    local c = tonumber(sql.QueryValue("SELECT COUNT(*) FROM 
darkrp_zspawns WHERE map = " .. sql.SQLStr(map) .. ";"))

    if c and c >= 1 then
        r = sql.QueryRow("SELECT * FROM darkrp_zspawns WHERE map = 
" .. sql.SQLStr(map) .. ";", math.random(1, c))
        en = ents.FindInSphere(Vector(r.x, r.y, r.z),50) // check 
as see if there are any entities around.

        for k, v in pairs( en ) do 
                if ( v:IsNPC() == true ) then 
                    //print ( "NPC Found!\n" ) for debugging 
purposes
                    return Vector(0,0,0) //NPC found so return 
0,0,0
                end 
        end 
     end   

    return Vector(r.x, r.y, r.z+25)  //spawn 25 off the ground in case we 
are on a hill or somethign silly like that.        

end

fix: so zombies don't spawn on top of each other.

Original issue reported on code.google.com by Enjia2000@gmail.com on 12 Mar 2009 at 8:50

GoogleCodeExporter commented 9 years ago
function MoveZombie() <--- should be commented out completly as setschedule is 
broken  
as far as i'm concerned. zombies still attack and wander about without it

also

in function spawnzombie change 

zombie1:SetPos(DB.RetrieveRandomZombieSpawnPos())

to

zombie1:SetPos(DB.RetrieveFreeZombieSpawnPos())

for each spawntype to use the new function

Original comment by Enjia2000@gmail.com on 12 Mar 2009 at 8:53

GoogleCodeExporter commented 9 years ago
Ok I'm going to add this code and you're going to be in the credits.

I just changed it a bit, I commented DB.RetrieveRandomZombieSpawnPos() out and 
called  
your function DB.RetrieveRandomZombieSpawnPos so I don't have to change 
main.lua.

Also:
if ( v:IsNPC() == true ) then
Little tip here, v:IsNPC() returns either true or false so basically you're 
doing
if (true == true) then, if it's an NPC and
if false == false then, if it's not an NPC.

it's better to do this:
if v:IsNPC() then 

They both work but this version is "more effective", I changed that too(minor 
change)

Original comment by fpeijnen...@gmail.com on 22 Mar 2009 at 6:52

GoogleCodeExporter commented 9 years ago
Wait this is wrong!
When it finds an NPC it just spawns the new NPC in Vector(0,0,0)!!!
That could be in the world and we don't want that.

I'll use my no player in player code

Original comment by fpeijnen...@gmail.com on 22 Mar 2009 at 6:59

GoogleCodeExporter commented 9 years ago
ya i'm fairly new to coding, i was just deleting all NPCs i found at 0,0,0, 
gonna 
work more on my modded darkrp server this week so i'll let you know what i 
figure out 
next =D

Original comment by Enjia2000@gmail.com on 23 Mar 2009 at 2:07

GoogleCodeExporter commented 9 years ago

Original comment by fpeijnen...@gmail.com on 29 Mar 2009 at 6:52