Jump to content

Slothbot make bot follow player but not attack


harryh

Recommended Posts

Posted

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

Posted

Maybe search for the attacking function and set a elementdata for the dog as "owner" and then check in the attacking function if he is following his owner, and if he is, don't attack him.

Posted

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)

 

Posted (edited)

You don't have to go client-side.

Just put

cancelEvent()

Inside the function handled by the event onBotFindEnemy

Edited by Gordon_G
Posted

Yes I thought that was what you had to do but it stops the dog following the player and it just stands doing nothing. Then if I make it follow again it starts attacking.

Posted (edited)

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
Posted

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)

 

Posted (edited)

In your first function, you don't define the value source.

 

So, in your second code, put 

sDog(source)

and set 

function sDog(source)

in your first.

instead of

sDog()

and 

function sDog()

 

Edited by Gordon_G
Posted

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)

 

Posted (edited)
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
Posted

Ah, I have found the problem. I have other scripts I have downloaded from the community that use teams so getPlayerTeam returns true meaning the codes are not executed. I guess ill have to either modify slothbot or just not use it. Such a shame. Thank you @Gordon_G 

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...