Jump to content

Destroying Blip Problem


Price.

Recommended Posts

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
  • MTA Team

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

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

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

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

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

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

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