Jump to content

[Error] Help please


Recommended Posts

function onPlayerQuit ( ) 
    if ( gotBag [ source ] ) then 
        destroyElement ( gotBag [ source ] ) 
        local x, y, z = getElementPosition ( source ) 
        local baga = createPickup ( x, y, z, 3, 1210 ) 
        local bagb = createObject ( 1210, 0, 0, 0 ) 
        addEventHandler ( "onPickupHit", baga, onPickupHit ) 
        bags [ baga ] = bagb 
        gotBag [ source ] = nil 
    end 
end 
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 

Yea..it works really fine...but i want to know...how to get the number of pickups still not removed? and how to check if the pickups being removed?

i ask about that because i'm looking to outputChatBox ("number of briefcases around the map"...pickups)... or when pickup be removed ... it says outputChatBox ("numbers of the briefcases now are "...now)

like this..i hope you got it... :)

Link to comment
  • Replies 67
  • Created
  • Last Reply

Top Posters In This Topic

You'll have to define a variable, then lower it when a pickup is taken.

hmm...i'm tried to do... but actually not work

see

     
    local bagNum = 7 
  
function howMany () 
        if gotBag [ source ] and triggerClientEvent (source, "buttonClick", source) then 
        if bagNum == 7 then 
        bagNum == 6 
            outputChatBox ("there's "..bagNum.."bags around the city now",source , 255, 255, 255, false) 
        end 
    end 
    addCommandHandler ("test", howMany) 

can you help me with this?

Link to comment
Post your current script ( whole script ).
    local pbags = 
    { 
        {2028.2314453125, 648.09765625, 11.366704940796}, 
        {2340.6474609375, 750.9208984375, 11.218271255493}, 
        {1632.525390625, 1035.7626953125, 13.769004821777}, 
        {1494.2626953125, 751.025390625, 29.161626815796}, 
        {1454.25, 751.05859375, 32.736267089844}, 
        {1533.3515625, 751.1181640625, 32.64266204834}, 
        {1427.3037109375, 1462.958984375, 10.8203125} 
    } 
    local bags = { } 
    local gotBag = { } 
      
    addEventHandler ( "onResourceStart", resourceRoot, 
        function ( ) 
            for _, i in ipairs ( pbags ) do 
                local baga = createPickup(i[1], i[2], i[3], 3, 1210 ) 
                local bagb = createObject ( 1210, 0, 0, 0 ) 
                addEventHandler ( "onPickupHit", baga, onPickupHit ) 
                bags [ baga ] = bagb 
            end 
        end 
    ) 
      
    function onPickupHit ( player ) 
        if ( not isPedInVehicle ( player ) and not isPedDead ( player ) and not gotBag [ player ] ) then 
            exports.bone_attach:attachElementToBone ( bags [ source ], player, 12, 0, 0.1, 0.3, 0, 180, 0 ) 
            gotBag [ player ] = bags [ source ] 
            destroyElement ( source ) 
        end 
    end 
    function onBtnClick ( ) 
        if ( gotBag [ source ] ) then 
            local money = math.random ( 1000, 2000 ) 
            givePlayerMoney ( source, money ) 
            destroyElement ( gotBag [ source ] ) 
            triggerClientEvent ( source, "WarningText", source, "reward", "You have rewarded and got ".. money .. "$ from the dealer!! Good Job Pro!" ) 
            outputChatBox ( "you have Rewarded and got ".. money .."$ from the dealer...You are PRO!! Good JOB!", source, 0, 255, 0, false ) 
            triggerClientEvent ( source,"winSound", source ) 
            gotBag [ source ] = nil 
        else 
            triggerClientEvent ( source, "WarningText", source, "reward", "You have to get the briefcase of weapons First!" ) 
        end 
    end 
    addEvent ( "reward", true ) 
    addEventHandler ( "reward", root, onBtnClick ) 
      
    function onPlayerQuit ( ) 
        if ( gotBag [ source ] ) then 
            destroyElement ( gotBag [ source ] ) 
            local x, y, z = getElementPosition ( source ) 
            local baga = createPickup ( x, y, z, 3, 1210 ) 
            local bagb = createObject ( 1210, 0, 0, 0 ) 
            addEventHandler ( "onPickupHit", baga, onPickupHit ) 
            bags [ baga ] = bagb 
            gotBag [ source ] = nil 
        end 
    end 
    addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 

Link to comment
local pbags = 
    { 
        {2028.2314453125, 648.09765625, 11.366704940796}, 
        {2340.6474609375, 750.9208984375, 11.218271255493}, 
        {1632.525390625, 1035.7626953125, 13.769004821777}, 
        {1494.2626953125, 751.025390625, 29.161626815796}, 
        {1454.25, 751.05859375, 32.736267089844}, 
        {1533.3515625, 751.1181640625, 32.64266204834}, 
        {1427.3037109375, 1462.958984375, 10.8203125} 
    } 
local bags = { } 
local gotBag = { } 
local totalBags = #pbags 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for _, i in ipairs ( pbags ) do 
            local baga = createPickup(i[1], i[2], i[3], 3, 1210 ) 
            local bagb = createObject ( 1210, 0, 0, 0 ) 
            addEventHandler ( "onPickupHit", baga, onPickupHit ) 
            bags [ baga ] = bagb 
        end 
    end 
) 
  
function onPickupHit ( player ) 
    if ( not isPedInVehicle ( player ) and not isPedDead ( player ) and not gotBag [ player ] ) then 
        exports.bone_attach:attachElementToBone ( bags [ source ], player, 12, 0, 0.1, 0.3, 0, 180, 0 ) 
        gotBag [ player ] = bags [ source ] 
        destroyElement ( source ) 
        totalBags = ( totalBags - 1 ) 
    end 
end 
  
function onBtnClick ( ) 
    if ( gotBag [ source ] ) then 
        local money = math.random ( 1000, 2000 ) 
        givePlayerMoney ( source, money ) 
        destroyElement ( gotBag [ source ] ) 
        triggerClientEvent ( source, "WarningText", source, "reward", "You have rewarded and got ".. money .. "$ from the dealer!! Good Job Pro!" ) 
        outputChatBox ( "you have Rewarded and got ".. money .."$ from the dealer...You are PRO!! Good JOB!", source, 0, 255, 0, false ) 
        triggerClientEvent ( source,"winSound", source ) 
        gotBag [ source ] = nil 
    else 
        triggerClientEvent ( source, "WarningText", source, "reward", "You have to get the briefcase of weapons First!" ) 
    end 
end 
addEvent ( "reward", true ) 
addEventHandler ( "reward", root, onBtnClick ) 
  
function onPlayerQuit ( ) 
    if ( gotBag [ source ] ) then 
        destroyElement ( gotBag [ source ] ) 
        local x, y, z = getElementPosition ( source ) 
        local baga = createPickup ( x, y, z, 3, 1210 ) 
        local bagb = createObject ( 1210, 0, 0, 0 ) 
        addEventHandler ( "onPickupHit", baga, onPickupHit ) 
        bags [ baga ] = bagb 
        gotBag [ source ] = nil 
        totalBags = ( totalBags + 1 ) 
    end 
end 
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 

Then you can use the variable "totalBags" to know how much bags are left.

Link to comment
local pbags = 
    { 
        {2028.2314453125, 648.09765625, 11.366704940796}, 
        {2340.6474609375, 750.9208984375, 11.218271255493}, 
        {1632.525390625, 1035.7626953125, 13.769004821777}, 
        {1494.2626953125, 751.025390625, 29.161626815796}, 
        {1454.25, 751.05859375, 32.736267089844}, 
        {1533.3515625, 751.1181640625, 32.64266204834}, 
        {1427.3037109375, 1462.958984375, 10.8203125} 
    } 
local bags = { } 
local gotBag = { } 
local totalBags = #pbags 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for _, i in ipairs ( pbags ) do 
            local baga = createPickup(i[1], i[2], i[3], 3, 1210 ) 
            local bagb = createObject ( 1210, 0, 0, 0 ) 
            addEventHandler ( "onPickupHit", baga, onPickupHit ) 
            bags [ baga ] = bagb 
        end 
    end 
) 
  
function onPickupHit ( player ) 
    if ( not isPedInVehicle ( player ) and not isPedDead ( player ) and not gotBag [ player ] ) then 
        exports.bone_attach:attachElementToBone ( bags [ source ], player, 12, 0, 0.1, 0.3, 0, 180, 0 ) 
        gotBag [ player ] = bags [ source ] 
        destroyElement ( source ) 
        totalBags = ( totalBags - 1 ) 
    end 
end 
  
function onBtnClick ( ) 
    if ( gotBag [ source ] ) then 
        local money = math.random ( 1000, 2000 ) 
        givePlayerMoney ( source, money ) 
        destroyElement ( gotBag [ source ] ) 
        triggerClientEvent ( source, "WarningText", source, "reward", "You have rewarded and got ".. money .. "$ from the dealer!! Good Job Pro!" ) 
        outputChatBox ( "you have Rewarded and got ".. money .."$ from the dealer...You are PRO!! Good JOB!", source, 0, 255, 0, false ) 
        triggerClientEvent ( source,"winSound", source ) 
        gotBag [ source ] = nil 
    else 
        triggerClientEvent ( source, "WarningText", source, "reward", "You have to get the briefcase of weapons First!" ) 
    end 
end 
addEvent ( "reward", true ) 
addEventHandler ( "reward", root, onBtnClick ) 
  
function onPlayerQuit ( ) 
    if ( gotBag [ source ] ) then 
        destroyElement ( gotBag [ source ] ) 
        local x, y, z = getElementPosition ( source ) 
        local baga = createPickup ( x, y, z, 3, 1210 ) 
        local bagb = createObject ( 1210, 0, 0, 0 ) 
        addEventHandler ( "onPickupHit", baga, onPickupHit ) 
        bags [ baga ] = bagb 
        gotBag [ source ] = nil 
        totalBags = ( totalBags + 1 ) 
    end 
end 
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 

Then you can use the variable "totalBags" to know how much bags are left.

Yeah ... Really nice...but after this i tried to show the bags numbers in label...but not works...please check :

client:

function bagNums (Tab,Text) 
        if Tab == "BagNum" then 
        guiSetText (BagsNums, Text) 
    end 
end 
addEvent ("howManyBags", true) 
addEventHandler ("howManyBags", getRootElement(), bagNums) 

server:

    function showBagNums (source) 
    triggerClientEvent (source, "howManyBags", source, "BagNum", "There are now "..totalBags.." bags available around the city") 
    end 
    addEventHandler ("onPlayerLogin", getRootElement(), showBagNums) 

I think the problem with the Event Handler?

Link to comment
You must trigger it everytime a bag is picked up.

hm..can you give me an example for that?

and i want it to be trigged when player click on btn..not on pickup.so the work will be in the button

and the script now

    local pbags = 
        { 
            {2028.2314453125, 648.09765625, 11.366704940796}, 
            {2340.6474609375, 750.9208984375, 11.218271255493}, 
            {1632.525390625, 1035.7626953125, 13.769004821777}, 
            {1494.2626953125, 751.025390625, 29.161626815796}, 
            {1454.25, 751.05859375, 32.736267089844}, 
            {1533.3515625, 751.1181640625, 32.64266204834}, 
            {1427.3037109375, 1462.958984375, 10.8203125} 
        } 
    local bags = { } 
    local gotBag = { } 
    local totalBags = #pbags 
      
    addEventHandler ( "onResourceStart", resourceRoot, 
        function ( ) 
            for _, i in ipairs ( pbags ) do 
                local baga = createPickup(i[1], i[2], i[3], 3, 1210 ) 
                local bagb = createObject ( 1210, 0, 0, 0 ) 
                addEventHandler ( "onPickupHit", baga, onPickupHit ) 
                bags [ baga ] = bagb 
            end 
        end 
    ) 
      
    function onPickupHit ( player ) 
        if ( not isPedInVehicle ( player ) and not isPedDead ( player ) and not gotBag [ player ] ) then 
            exports.bone_attach:attachElementToBone ( bags [ source ], player, 12, 0, 0.1, 0.3, 0, 180, 0 ) 
            gotBag [ player ] = bags [ source ] 
            destroyElement ( source ) 
        end 
    end 
      
    function onBtnClick ( ) 
        if ( gotBag [ source ] ) then 
            local money = math.random ( 1000, 2000 ) 
            givePlayerMoney ( source, money ) 
            destroyElement ( gotBag [ source ] ) 
            triggerClientEvent ( source, "WarningText", source, "reward", "You have rewarded and got ".. money .. "$ from the dealer!! Good Job Pro!" ) 
            outputChatBox ( "you have Rewarded and got ".. money .."$ from the dealer...You are PRO!! Good JOB!", source, 0, 255, 0, false ) 
            triggerClientEvent ( source,"winSound", source ) 
            gotBag [ source ] = nil 
            totalBags = ( totalBags - 1 ) 
        else 
            triggerClientEvent ( source, "WarningText", source, "reward", "You have to get the briefcase of weapons First!" ) 
        end 
    end 
    addEvent ( "reward", true ) 
    addEventHandler ( "reward", root, onBtnClick ) 
      
    function onPlayerQuit ( ) 
        if ( gotBag [ source ] ) then 
            destroyElement ( gotBag [ source ] ) 
            local x, y, z = getElementPosition ( source ) 
            local baga = createPickup ( x, y, z, 3, 1210 ) 
            local bagb = createObject ( 1210, 0, 0, 0 ) 
            addEventHandler ( "onPickupHit", baga, onPickupHit ) 
            bags [ baga ] = bagb 
            gotBag [ source ] = nil 
        end 
    end 
    addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 
     
    function showBagNums () 
    triggerClientEvent (source, "howManyBags", source, "BagNum", "There are now "..totalBags.." bags available around the city") 
    end 
    addEventHandler ("onPlayerLogin", getRootElement(), showBagNums) 

client:

function bagNums (Tab,Text) 
        if Tab == "BagNum" then 
        guiSetText (BagsNums, Text) 
    end 
end 
addEvent ("howManyBags", true) 
addEventHandler ("howManyBags", getRootElement(), bagNums) 

not the full client..but another another functions no need in this situation

Link to comment
triggerClientEvent ( root, "howManyBags", root, "BagNum", "There are now "..totalBags.." bags available around the city") 

Add that after givePlayerMoney.

Yeah.....actually puted it after totalBags...then worked :) because i want to low the number before shows it..and Thanks a lot man..you helped me a lot here :D...Big THANKS..and thanks to tapl too :)

            totalBags = ( totalBags - 1 ) 
            triggerClientEvent ( root, "howManyBags", root, "BagNum", "There are now "..totalBags.." bags available around the city") 

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