harryh Posted March 18, 2017 Share Posted March 18, 2017 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
NeXuS™ Posted March 18, 2017 Share Posted March 18, 2017 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. Link to comment
Gordon_G Posted March 18, 2017 Share Posted March 18, 2017 https://wiki.multitheftauto.com/wiki/Slothman/Slothbot#onBotFindEnemy Just make a check for the source who is the Enemy, if you don't want him to be attacked use : cancelEvent() Link to comment
harryh Posted March 19, 2017 Author Share Posted March 19, 2017 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
Gordon_G Posted March 19, 2017 Share Posted March 19, 2017 (edited) You don't have to go client-side. Just put cancelEvent() Inside the function handled by the event onBotFindEnemy Edited March 19, 2017 by Gordon_G Link to comment
harryh Posted March 19, 2017 Author Share Posted March 19, 2017 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. Link to comment
Gordon_G Posted March 19, 2017 Share Posted March 19, 2017 (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 March 19, 2017 by Gordon_G 1 Link to comment
harryh Posted March 19, 2017 Author Share Posted March 19, 2017 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
Gordon_G Posted March 19, 2017 Share Posted March 19, 2017 (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 March 19, 2017 by Gordon_G Link to comment
harryh Posted March 19, 2017 Author Share Posted March 19, 2017 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
Gordon_G Posted March 19, 2017 Share Posted March 19, 2017 (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 March 19, 2017 by Gordon_G Link to comment
harryh Posted March 19, 2017 Author Share Posted March 19, 2017 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 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now