Jump to content

Slothbot make bot follow player but not attack


harryh

Recommended Posts

Hi I am using slothbot to spawn in a ped to follow my player around the map. When the ped spawns it starts attacking the player it is following.

theDog = slothbot:spawnBot(x, y+1, z, 0, getDInfo["DogSkin"],0,0,nil,0,"following", source)
slothbot:setBotFollow(theDog, source)

How can I make him follow player and not attack without disabling his attack ability completely using(setBotAttackEnabled) as I will write a command to attack other players.

 

Thanks

Link to comment

Hi, I cannot seem to get it to work and no errors are returned in the console. The dog still follows me and attacks me

Here is my code

Server:

 

theDog = slothbot:spawnBot(...)
function dogPlayerCheck()
    triggerClientEvent("checkPlayer" ,client, theDog)
end
addEventHandler("onBotFindEnemy", theDog, dogPlayerCheck)

Client:

function checkPlayer(theDog)
    if theDog then
        addEventHandler("onClientPedWeaponFire", theDog, cancelEvent)
    end    
end
addEvent("checkPlayer", true)
addEventHandler("checkPlayer", getRootElement(), checkPlayer)

 

Link to comment

I see, I see.

 

Slothbot works by team ; if you don't want to modify the slothbot's source code, put the player and the dog in the same team when the dog is created.

createTeam() -- create a team where the player and the dog will be

setPlayerTeam()-- set the  player inside a team

element spawnBot ( float x, float y, float z, int rotation = 0, [ int skinID = 0, int interior = 0, int dimension = 0, HERE PUT THE TEAM WHERE THE PLAYER AND DOG WILL BE, ... ] )

-- You can get the player team with to set it for the dog
getPlayerTeam()

 

Edited by Gordon_G
  • Like 1
Link to comment

Hi, @Gordon_G Still not working, no errors in the console and my debug string says that the team has been set but the dog now just stands still.

function sDog()
    if loadPlayerInfo() then
        local x, y, z = getElementPosition(source)
        local theTeam = getPlayerTeam(source)
        theDog = slothbot:spawnBot(x, y+1, z, 0, getDInfo["DogSkin"],0,0,theTeam,0,"following", source)
        
        
        setElementData(source, "hisDog", theDog)
        --addEventHandler("onBotFindEnemy", theDog, dogPlayerCheck)
    end
end


 

function createTeams()
    if not getPlayerTeam(source) then
        local myTeam = getPlayerName(source)
        createTeam(myTeam)
        setPlayerTeam(source, getTeamFromName(myTeam))
        print("Team set" .. getTeamName(getPlayerTeam(source)) )
        sDog()
    end
end
addEvent("dogspawn", true)
addEventHandler("dogspawn", getRootElement(), createTeams)

 

Link to comment

No errors again and exact same problem:(

 


function sDog(source)
	if loadPlayerInfo() then
		local x, y, z = getElementPosition(source)
		local theTeam = getPlayerTeam(source)
		theDog = slothbot:spawnBot(x, y+1, z, 0, getDInfo["DogSkin"],0,0,theTeam,0,"following", source)
		
		
		setElementData(source, "hisDog", theDog)
		--addEventHandler("onBotFindEnemy", theDog, dogPlayerCheck)
	end
end



function createTeams()
	if not getPlayerTeam(source) then
		local myTeam = getPlayerName(source)
		createTeam(myTeam)
		setPlayerTeam(source, getTeamFromName(myTeam))
		print("Team set" .. getTeamName(getPlayerTeam(source)) )
		sDog(source)
	end
end
addEvent("dogspawn", true)
addEventHandler("dogspawn", getRootElement(), createTeams)

 

Link to comment
function sDog(source)
		local x, y, z = getElementPosition(source)
		local theTeam = getPlayerTeam(source)
		theDog = exports.slothbot:spawnBot(x, y+1, z, 0, 50,0,0,theTeam,0,"following", source)
		setElementData(source, "hisDog", theDog)
end



function createTeams(source)
	if not getPlayerTeam(source) then
		local myTeam = getPlayerName(source)
		createTeam(myTeam)
		setPlayerTeam(source, getTeamFromName(myTeam))
		print("Team set" .. getTeamName(getPlayerTeam(source)) )
		sDog(source)
	end
end
addCommandHandler( "my", createTeams)

Try this on your server with the command /my

It worked for me (when the bot spawn he doesn't move but, when I move, he moves).

 

(it's just a test to identify the issue)

Edited by Gordon_G
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...