Price. Posted November 4, 2014 Share Posted November 4, 2014 I've got this problem, I wanna attach a blip to a player i created a function for that but when I destroy blip addEventHandler returns nill, expected function at argument 3, got nill I want to attach the blip to player and when he dies the blip is destroyed function Blip (player) local myplayer = localPlayer() local x, y, z = getElementPosition( myPlayer ) blip = createBlip( x, y, z, 20, myPlayer ) setElementParent( blip, myPlayer ) addEvent("onDes", true) addEventHandler("onDes", getRootElement, Blip) function destroyBlipAttachedTo ( player ) local attached = getAttachedElements ( player ) if not attached then return end for index , attachedElement in pairs ( attached ) do if getElementType ( attachedElement ) == "blip" then destroyElement ( attachedElement ) outputChatBox("APB has been Jailed Successfully", source, 0, 55, 255) end end end end addEventHandler( "onPlayerWasted", getRootElement(), destroyBlipAttachedTo) Link to comment
Woovie Posted November 4, 2014 Share Posted November 4, 2014 Line 12 I assume is the error. Line 1 is function "Blip" but it doesn't even have an end or do anything? Link to comment
Price. Posted November 4, 2014 Author Share Posted November 4, 2014 works great but got error when I try to place the blip, when I click on the button to place blip gives me this error attempt to call global 'localPlayer' (a nil value) same with thePlayer Link to comment
MTA Team botder Posted November 4, 2014 MTA Team Share Posted November 4, 2014 Let's get this through: function Blip (player) The function has no ending (supposed to be at line 10) local myplayer = localPlayer() The "function" localPlayer is not a function (that makes the line actually pointless) and then the variable exists only clientside - I assume that it's a serverside script because you used onPlayerWasted local x, y, z = getElementPosition( myPlayer ) blip = createBlip( x, y, z, 20, myPlayer ) setElementParent( blip, myPlayer ) These lines will fail by default, because your variable "myplayer" is nil (use your parameter "player" instead) function destroyBlipAttachedTo ( player ) ... end addEventHandler( "onPlayerWasted", getRootElement(), destroyBlipAttachedTo) The event OnPlayerWasted actually gives you "totalAmmo" as first parameter (you used it as player). Delete it and use the hidden variable "source" for the player element. Link to comment
Price. Posted November 4, 2014 Author Share Posted November 4, 2014 I want to create blip attached to a player and keeps following him like "attachedTo" him and when he dies or quit the blip gets destroyed got few errors just need to know how to solve this script function Blip () local myplayer = getElementType ( p ) local x, y, z = getElementPosition( p ) blip = createBlip( x, y, z, 20,p ) setElementParent( blip, p ) end addEvent("onDes", true) addEventHandler("onDes", getRootElement(), Blip) function destroyBlipAttachedTo ( player ) local attached = getAttachedElements ( player ) if not attached then return end for index , attachedElement in pairs ( attached ) do if getElementType ( attachedElement ) == "blip" then destroyElement ( attachedElement ) outputChatBox("APB has been Jailed Successfully", source, 0, 55, 255) end end end addEventHandler( "onPlayerWasted", getRootElement(), destroyBlipAttachedTo) bad argument @ 'createBlip' [Expected vector3 at argument 1, got boolean], Bad argument @ 'setElementParent' [Expected element at argument 1, got boolean] Link to comment
rtx Posted November 5, 2014 Share Posted November 5, 2014 Have you declared the variable 'p' ? Link to comment
Price. Posted November 5, 2014 Author Share Posted November 5, 2014 not really, but Is P right anyways? Link to comment
Woovie Posted November 5, 2014 Share Posted November 5, 2014 Do you know what a variable is? Link to comment
Price. Posted November 5, 2014 Author Share Posted November 5, 2014 ahhh yes local players source ...etc I just having problem with that I cant make this work Link to comment
MTA Team botder Posted November 5, 2014 MTA Team Share Posted November 5, 2014 It looks like you have no idea what these things are doing. Is that script now clientside or serverside? Link to comment
Price. Posted November 5, 2014 Author Share Posted November 5, 2014 that's server side to destroy blip Link to comment
Mr_Moose Posted November 5, 2014 Share Posted November 5, 2014 There are so many errors so it's better to just restart from the beginning, first of all, when scripting on the server side you need to know where your player is defined, you're making a call from client side with triggerServerEvent to the function Blip I suppose? then you have your player in the variable 'client' if the client side part is written correctly. function Blip () local x, y, z = getElementPosition(client) local blip = createBlip( x, y, z, 20 ) setElementParent( blip, client ) end addEvent("onDes", true) addEventHandler("onDes", getRootElement(), Blip) function destroyBlipAttachedTo ( player ) local attached = getAttachedElements ( player ) if not attached then return end for index , attachedElement in pairs ( attached ) do if getElementType ( attachedElement ) == "blip" then destroyElement ( attachedElement ) outputChatBox("APB has been Jailed Successfully", root, 0, 55, 255) end end addEventHandler( "onPlayerWasted", getRootElement(), destroyBlipAttachedTo) Destroy function had one 'end' to much but you never got there due to the earlier errors, it should be fixed here so try it and look at it carefully to find out what changes was made to make it work. Link to comment
MTA Team botder Posted November 6, 2014 MTA Team Share Posted November 6, 2014 function destroyBlipAttachedTo ( player ) local attached = getAttachedElements ( player ) That will never work, because the player is actually stored in the variable source. Link to comment
Price. Posted November 6, 2014 Author Share Posted November 6, 2014 so what to do then? still brutus's code hasn't worked Link to comment
Mr_Moose Posted November 6, 2014 Share Posted November 6, 2014 As I said, lot's of errors get's confusing in the length, listen to what Necktrox said here, destroyBlipAttachedTo is called by an event trigger onPlayerWasted, source is the dead player and four other parameters are passed to the function which must be handled as well, ammo, attacker, weapon and bodypart. function destroyBlipAttachedTo(ammo, attacker, weapon, bodypart) local attached = getAttachedElements(source) if not attached then return end for index , attachedElement in pairs (attached) do if getElementType(attachedElement) == "blip" then destroyElement(attachedElement) outputChatBox("APB has been Jailed Successfully", root, 0, 55, 255) end end addEventHandler("onPlayerWasted", root, destroyBlipAttachedTo) Try at least, and don't be afraid of the wiki, there's a lot of useful information there. Link to comment
Price. Posted November 6, 2014 Author Share Posted November 6, 2014 this function is not my biggest fears, for now I'm still having lots of troubles because of invalid variables in this function function Blip () local x, y, z = getElementPosition(client) local blip = createBlip( x, y, z, 20 ) setElementParent( blip, client ) end addEvent("onDes", true) addEventHandler("onDes", getRootElement(), Blip) I'm still getting lots of errors from all "client" and yes I'am triggering it from client side but... still having bad argument because of client. Link to comment
MTA Team botder Posted November 6, 2014 MTA Team Share Posted November 6, 2014 Show us the line where you trigger that event. Link to comment
Price. Posted November 6, 2014 Author Share Posted November 6, 2014 that's the client side where I got the entire errors function Blip () local x, y, z = getElementPosition(client) local blip = createBlip( x, y, z, 20 ) setElementParent( blip, client ) end addEvent("onDes", true) addEventHandler("onDes", getRootElement(), Blip) client elseif ( source == placeAPBbutton ) then --- APB if ( sel ~= -1 ) then triggerServerEvent("onDes",localPlayer,text) end 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