
harryh
Members-
Posts
108 -
Joined
-
Last visited
Everything posted by harryh
-
Try this function onPlayerTarget (targetElem, thePlayer ) if getElementType ( targetElem ) == "object" and getElementModel ( targetElem ) == 1557 then local px, py, pz = getElementPosition(source) local x, y, z = getElementPosition(targetElem) if tonumber(getDistanceBetweenPoints3D(x, y, z, getElementPosition(source))) < 20 then toggleControl ( source, "fire", false ) else toggleControl ( source, "fire", true ) end else outputChatBox("No Target", source) end end addEventHandler ( "onPlayerTarget", root, onPlayerTarget ) Also expected element = boolean means there was no target so targetElem was returning false meaning all code below this if ( getElementModel ( targetElem ) == 1557 ) then will not be triggered.
-
Model is not defined in the script above. Model just equals a number. (1557) Also, onClientResourceStart means that this code will only run when the resource starts and it will never run again.
-
Also, What is with this. It works within the GUI editor but not when its put into practice. This relative thing doesn't work. Why does it work here?
-
Hi, thank you but I have other variables that reference to all the GUI items in my code above. Therefore, I cant use edit boxes so this will not work. I will try and change too see what happens
-
Hi, Im a bit confused how to use this above^ I used GUI editor to change all of the GUI items to relative but it still does the same thing: DogCreate.Window = guiCreateWindow(0.79, 0.11, 0.17, 0.25, "", true) DogCreate.BuyButton = guiCreateButton(0.07, 0.76, 0.86, 0.20, "Purchase Dog", true, DogCreate.Window) DogCreate.NameLab = guiCreateLabel(0.03, 0.24, 0.23, 0.13, "NAME:", true, DogCreate.Window) DogCreate.BreedLab = guiCreateLabel(0.02, 0.39, 0.24, 0.09, "BREED:", true, DogCreate.Window) DogCreate.MaLab = guiCreateLabel(0.40, 0.61, 0.05, 0.06, " M", true, DogCreate.Window) DogCreate.FeLab = guiCreateLabel(0.60, 0.61, 0.05, 0.06, " F", true, DogCreate.Window) DogCreate.WindowLab = guiCreateLabel(0.24, 0.05, 0.56, 0.15, "Dog Creator", true, DogCreate.Window) DogCreate.DogColorCombo = guiCreateComboBox(0.28, 0.50, 0.63, 0.12, "", true, DogCreate.Window) DogCreate.ColorLab = guiCreateLabel(0.02, 0.49, 0.24, 0.09, "Colour:", true, DogCreate.Window) DogCreate.BreedBox = guiCreateComboBox(0.28, 0.39, 0.63, 0.12, "", true, DogCreate.Window) DogCreate.MaleRadio = guiCreateRadioButton(0.40, 0.68, 0.04, 0.05, "", true, DogCreate.Window) DogCreate.FemaleRadio = guiCreateRadioButton(0.59, 0.67, 0.04, 0.05, "", true, DogCreate.Window) DogCreate.NameBox = guiCreateEdit(0.28, 0.23, 0.63, 0.12, "", true, DogCreate.Window)
-
I have told been that if I select relative position in the main parent window in gui editor it would work for all resolutions However is doesn't My Res: 1920*1080 His Res: 1280*720 His Screen: DogCreate.Window = guiCreateWindow(0.79, 0.11, 0.17, 0.25, "", true) guiWindowSetMovable(DogCreate.Window, false) guiWindowSetSizable(DogCreate.Window, false) guiSetProperty(DogCreate.Window, "TitlebarEnabled", "False") DogCreate.NameBox = guiCreateEdit(0.28, 0.23, 0.63, 0.12, "", true, DogCreate.Window) DogCreate.BreedBox = guiCreateComboBox(0.28, 0.39, 0.63, 0.12, "", true, DogCreate.Window) guiComboBoxAddItem(DogCreate.BreedBox, "German Sheperd") guiComboBoxAddItem(DogCreate.BreedBox, "Rottweiler") guiComboBoxAddItem(DogCreate.BreedBox, "Golden Retriever") guiComboBoxAddItem(DogCreate.BreedBox, "Pitbull") DogCreate.MaleRadio = guiCreateRadioButton(0.40, 0.68, 0.04, 0.05, "", true, DogCreate.Window) DogCreate.FemaleRadio = guiCreateRadioButton(0.60, 0.68, 0.04, 0.05, "", true, DogCreate.Window) DogCreate.BuyButton = guiCreateButton(0.07, 0.76, 0.86, 0.20, "Purchase Dog", true, DogCreate.Window) DogCreate.NameLab = guiCreateLabel(9, 64, 76, 36, "NAME:", false, DogCreate.Window) DogCreate.BreedLab = guiCreateLabel(8, 106, 77, 24, "BREED:", false, DogCreate.Window) DogCreate.MaLab = guiCreateLabel(0.40, 0.61, 0.05, 0.06, " M", true, DogCreate.Window) DogCreate.FeLab = guiCreateLabel(0.60, 0.61, 0.05, 0.06, " F", true, DogCreate.Window) DogCreate.WindowLab = guiCreateLabel(79, 14, 184, 40, "Dog Creator", false, DogCreate.Window) DogCreate.ColorLab = guiCreateLabel(8, 131, 77, 25, "Colour:", false, DogCreate.Window)
-
Yes I see. Thank you. @Gordon_G
-
Hi, so I have never really used event handlers properly so if I trigger a client event using the element getLocalPlayer() what must I put in the server add event handler to return the same element. I put getRootElement() but I think thats wrong. Code below is just an example of how I use addEventHandler Client: function check() triggerServerEvent("stuff", getLocalPlayer()) end addEventHandler("check", getLocalPlayer(), theFunction) server: addEventHandler("stuff", getRootElement(), stuffFunction) <------------ I would use this if calling in serverside because I dont know how to get the player. Normally I use source inside the function because that returns what executed the command or event Thanks
-
Hi, I cant seem to call a serverside event which runs a function to get infomation from the database then return it to clientside to update the clientside text label. Client: triggerServerEvent( "checkDog", getLocalPlayer( ) ) guiSetText( DogPanel.dogName, getDInfo["Name"] ) server: function loadPlayerInfo() local dbid = getElementData(source, "account:id") getDInfo = mysql:query_fetch_assoc("SELECT * FROM dogs WHERE pID = '" ..dbid.."'") gettheplayer = getPlayerName(source) outputChatBox("dbid:" ..tostring(dbid)) --InfoArray = getDInfo(result) if getDInfo then setElementData(source, "haveDog", true) outputChatBox("Your Dog is Called " ..getDInfo["Name"]) dogInfo = getDInfo getSkin = getDInfo["DogSkin"] return true, getDInfo elseif not getDInfo then setElementData(source, "haveDog", false) --No dog saved to DB outputChatBox("No Dog In DB.") else outputChatBox("Fatal Error has occured please contact administrator.") end end addEvent("checkDog", true) addEventHandler("checkDog", getRootElement(), loadPlayerInfo) addCommandHandler("loaddogs", loadPlayerInfo)
-
EDIT: Fixed just need to put in data/packages/user instead of Packages/user Sublime doesn't work either. No Lua MTA SA Directory is documents as I am using portable version
-
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
-
Thanks I will just use sublime.
-
Hi,I did try to download it but the download link is defunct. Unfortunately.
-
Yep doesn't work though. Also inside the MTA Lua xml I have checked the auto completion langauge is set to MTA-Lua I have Syntax Highlighting: The Langauge selected: And the API: in the correct folder:
-
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)
-
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)
-
Hi, not sure if this is the correct section but I am using his User defined langauge and the API autocomplete xml but it just doesn't do anything. The syntax highlighting changes but auto complete doesnt work and there are no functions in the function list.
-
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.
-
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)
-
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
-
Thank you for your help @Gordon_G @TheMOG
-
What functions would I need to use to get a ped to follow a player with a walking animation. Unsure how I would do it as with setElementPosition it will teleport. and not walk. Puedocode: getPedInformation createPed with info spawn Ped Set to follow the player In and out of cars etc.
-
I have fixed it. was due to guiClearComboBox in a loop