Jump to content

Help


MAB

Recommended Posts

i am making a Ghost town script using slothbot but there is a addEventHandler problem at although it worked before

Help! the problem happened because the bot isn't getting spawned i don't why

local GhostRadar = createRadarArea ( -465.25684, 2173.76489, 130, 110, 255, 0, 0, 255 ) 
local GhostCol = createColCuboid ( -465.25684, 2173.76489, 40, 127, 100, 20 ) 
createBlip( -399.48187, 2233.17896, 42.42969, 23 ) 
addEvent ( "onBotWasted", true ) 
addEvent ( "onBotSpawned", true ) 
  
function onHit ( hitElement ) 
     if getElementType ( hitElement ) == "player" then 
            x,y,z = getElementPosition ( hitElement ) 
            Timer = setTimer ( Spawn, 5*1000, 1) 
     end 
     if getElementType ( hitElement ) == "vehicle" then 
        setElementHealth ( hitElement, 25 ) 
     end 
end 
addEventHandler ( "onColShapeHit", GhostCol, onHit ) 
  
function Spawn () 
bot1 = exports["slothbot"]:spawnBot ( x + 5, y, z, 90, math.random ( 1, 100 ), 0, 0, nil, math.random ( 2, 9 ), "chasing" ) 
bot2 = exports["slothbot"]:spawnBot ( x, y + 5, z, 90, math.random ( 1, 100 ), 0, 0, nil, math.random ( 2, 9 ), "chasing" ) 
end 
  
function Events () 
        if bot1 and bot2 then 
          addEventHandler ( "onBotWasted", bot1, OnWasted ) 
          addEventHandler ( "onBotWasted", bot2, OnWasted ) 
          addEventHandler ( "onBotSpawned", bot1, OnSpawn ) 
          addEventHandler ( "onBotSpawned", bot2, OnSpawn ) 
       end 
end 
addEventHandler ( "onBotSpawned", bot1, Events ) 
addEventHandler ( "onBotSpawned", bot2, Events ) 
  
  
function OnWasted ( attacker, weapon, bodypart ) 
         if attacker then 
         if isElementWithinColShape ( attacker, GhostCol ) then 
               if bodypart ~= 9 then 
                  givePlayerMoney ( attacker, 1000 ) 
               end 
                  if bodypart == 9 then 
                     givePlayerMoney ( attacker, 2000 ) 
                 end 
         end 
         end 
end 
  
function OnSpawn () 
players = getElementsByType( "player", GhostCol ) 
setBotChase ( source, players ) 
end 
  
function onLeave ( leaveElement ) 
  if Timer then 
     killTimer ( Timer ) 
  end 
end 
addEventHandler ( "onColShapeLeave", GhostCol, onLeave ) 

Link to comment

try this:

local GhostRadar = createRadarArea ( -465.25684, 2173.76489, 130, 110, 255, 0, 0, 255 ) 
local GhostCol = createColCuboid ( -465.25684, 2173.76489, 40, 127, 100, 20 ) 
createBlip( -399.48187, 2233.17896, 42.42969, 23 ) 
addEvent ( "onBotWasted", true ) 
addEvent ( "onBotSpawned", true ) 
  
function onHit ( hitElement ) 
     if getElementType ( hitElement ) == "player" then 
            x,y,z = getElementPosition ( hitElement ) 
            Timer = setTimer ( Spawn, 5*1000, 1) 
     end 
     if getElementType ( hitElement ) == "vehicle" then 
        setElementHealth ( hitElement, 25 ) 
     end 
end 
addEventHandler ( "onColShapeHit", GhostCol, onHit ) 
  
function Spawn () 
bot1 = exports["slothbot"]:spawnBot ( x + 5, y, z, 90, math.random ( 1, 100 ), 0, 0, nil, math.random ( 2, 9 ), "chasing" ) 
bot2 = exports["slothbot"]:spawnBot ( x, y + 5, z, 90, math.random ( 1, 100 ), 0, 0, nil, math.random ( 2, 9 ), "chasing" ) 
addEventHandler ( "onBotSpawned", bot1, Events ) 
addEventHandler ( "onBotSpawned", bot2, Events ) 
end 
  
function Events () 
        if bot1 and bot2 then 
          addEventHandler ( "onBotWasted", bot1, OnWasted ) 
          addEventHandler ( "onBotWasted", bot2, OnWasted ) 
          addEventHandler ( "onBotSpawned", bot1, OnSpawn ) 
          addEventHandler ( "onBotSpawned", bot2, OnSpawn ) 
       end 
end 
  
  
  
function OnWasted ( attacker, weapon, bodypart ) 
         if attacker then 
         if isElementWithinColShape ( attacker, GhostCol ) then 
               if bodypart ~= 9 then 
                  givePlayerMoney ( attacker, 1000 ) 
               end 
                  if bodypart == 9 then 
                     givePlayerMoney ( attacker, 2000 ) 
                 end 
         end 
         end 
end 
  
function OnSpawn () 
players = getElementsByType( "player", GhostCol ) 
setBotChase ( source, players ) 
end 
  
function onLeave ( leaveElement ) 
  if Timer then 
     killTimer ( Timer ) 
  end 
end 
addEventHandler ( "onColShapeLeave", GhostCol, onLeave ) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...