Jump to content

AccountData Help


LasHa

Recommended Posts

Guys help me please? :3 i tried a lot things but nothing worked. I want to make that when player enters marker, account data saved "finished stunts" and when player relogins the color and the counts of stunt were same as before relogin. :3 I'm beginner scripter and i don't think that i started too low ^_^ Please Help <3

local TimeTable = {} 
local waitTime = 3000 -- 3 seconds 
local Blips = {} 
local details = {} 
local Entred = {} 
local Markers = { 
{522, 1986, -1478.1, 21.5, 17.500, "Test Stunt #1"}, -- Marker 1 
{522, 1114, -1822, 33.5, 17.500,"Test Stunt #2"}, -- Marker 2 
{522, 776.8, -1036, 39.5, 9000,"Stunt Name Here"}, -- Marker 3 
{522, 1313, -1163, 41, 7500,"Stunt Name Here"}, -- Marker 4 
{522, 1404, -806, 85, 7500,"Stunt Name Here"}, -- Marker 5 
{522, 775.7, -1060.5, 33.2, 5000,"Stunt Name Here"}, -- Marker 6 
} 
  
for i , v in pairs (Markers) do 
    HitMarker = createMarker ( v[2], v[3], v[4], "corona", 1.20, 255, 0, 0, 255 ) 
    Blips[HitMarker] = createBlipAttachedTo( HitMarker, 0 ) 
    details[HitMarker] = {v[1],v[5],v[6]} 
end 
  
function allowedVehicles( hitElement, matchingDimension ) 
    if matchingDimension and isElement(hitElement) and getElementType(hitElement) == "player" then 
        if isPedInVehicle ( hitElement ) then 
            local vehicle = getPedOccupiedVehicle ( hitElement ) 
            if vehicle then 
            if Entred[hitElement] == source then 
                outputChatBox("Sorry you can't enter the marker twice" , hitElement,255,0,0) 
                return 
            end 
            local theTable = details[source] 
            if (theTable) then       
            local model, cash, name = details[source][1], details[source][2], details[source][3] 
                if getElementModel ( vehicle ) == model then 
                    TimeTable[hitElement] = setTimer(StuntComplete, waitTime, 1, hitElement,source,cash,name) 
                    setElementData ( hitElement, "entered.marker", true ) 
                    Entred[hitElement] = source 
                    else 
                    outputChatBox ( "You have entered in Stunt with wrong vehicle", hitElement, 255, 0, 0 ) 
                end 
            end 
        end 
    end 
    end 
end 
addEventHandler( "onMarkerHit", resourceRoot, allowedVehicles ) 
  
function StuntComplete (player,marker,cash,markerName) 
    if isElement ( player ) then 
        if getElementData ( player, "entered.marker" ) then             
            givePlayerMoney ( player, tonumber(cash)) 
            outputChatBox ( "You have completed the Stunt and earned "..tonumber(cash).."$", player, 0, 255, 0 ) 
            if isElement( Blips[marker] ) then 
            setBlipColor ( Blips[marker], 0, 255, 0, 255 ) 
            setMarkerColor (marker,0, 255, 0, 255 ) 
            end 
            local playerAccount = getPlayerAccount ( player ) 
            if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
            local totalStunts = getAccountData ( playerAccount, "totalStunts" ) or 0 
            local name = markerName 
            local rb,gb,bb,ab = getBlipColor ( Blips[marker] ) 
            local rm,gm,bm,am = getMarkerColor ( marker ) 
            local Det = toJSON({name,rb,gb,bb,ab,rm,gm,bm,am}) 
            setAccountData ( playerAccount, "Details", Det ) 
            setAccountData( playerAccount, "totalStunts" , tonumber(totalStunts)+1) 
            end 
        end 
    end 
end 
  
addEventHandler ( "onMarkerLeave", resourceRoot, 
    function ( leaveElement ) 
        if ( isElement ( leaveElement ) and getElementType ( leaveElement ) == "player" ) then 
            setElementData ( leaveElement, "entered.marker", false ) 
            outputChatBox("You failed the Stunt!", leaveElement, 255, 0, 0) 
        end 
    end 
) 
  
function stuntsFinished ( player ) 
    if isElement(player) then 
        local playerAccount = getPlayerAccount ( player ) 
        if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local count = getAccountData( playerAccount, "totalStunts" ) or 0 
        outputChatBox( "You have finished "..tonumber(count).."/512 Stunts", player, 0, 255, 0) 
        end 
    end 
end 
addCommandHandler("fstunts", stuntsFinished) 
  
function Load (_,cur) 
    local Det = getAccountData(cur,"Details") 
    if Det then 
    local marName,rb,gb,bb,ab,rm,gm,bm,am = unpack( fromJSON(Det)) 
    for i , mar in pairs (getElementsByType("marker")) do 
        local theTable = details[mar] 
            if (theTable) then       
            local name = details[mar][3] 
                if name == tostring(marName) then 
                    setMarkerColor (mar,tonumber(rm),tonumber(gm),tonumber(bm),tonumber(am)) 
                end 
            end             
        end 
    end 
end 
addEventHandler("onPlayerLogin",root,Load) 

Link to comment
Can you help me? That's why i am here!

Fixed many things for you and your code is working fine now.

local Blips = {} 
local details = {} 
local Entred = {} 
  
local Markers = { 
{522, 1986, -1478.1, 21.5, 17.500, "Test Stunt #1"}, -- Marker 1 
{522, 1114, -1822, 33.5, 17.500,"Test Stunt #2"}, -- Marker 2 
{522, 776.8, -1036, 39.5, 9000,"Stunt Name Here"}, -- Marker 3 
{522, 1313, -1163, 41, 7500,"Stunt Name Here"}, -- Marker 4 
{522, 1404, -806, 85, 7500,"Stunt Name Here"}, -- Marker 5 
{522, 775.7, -1060.5, 33.2, 5000,"Stunt Name Here"}, -- Marker 6 
} 
  
function allowedVehicles( hitElement, matchingDimension ) 
    if matchingDimension and isElement(hitElement) and getElementType(hitElement) == "player" then 
        if isPedInVehicle ( hitElement ) then 
            local vehicle = getPedOccupiedVehicle ( hitElement ) 
            if vehicle then 
                if Entred[hitElement] == source then 
                    outputChatBox("Sorry you can't enter the marker twice" , hitElement,255,0,0) 
                    return 
                end 
                 
                local theTable = details[source] 
                if (theTable) then       
                    local model, cash, name = details[source][1], details[source][2], details[source][3] 
                        if getElementModel ( vehicle ) == model then 
                            StuntComplete(hitElement,source,cash,name) -- You don't need a timer here  
                            Entred[hitElement] = source 
                        else 
                        outputChatBox ( "You have entered in Stunt with wrong vehicle", hitElement, 255, 0, 0 ) 
                    end 
                end 
            end 
        end 
    end 
end 
  
  
function StuntComplete (player,marker,cash,markerName) 
    if isElement ( player ) then             
        givePlayerMoney ( player, tonumber(cash)) 
        outputChatBox ( "You have completed the Stunt and earned "..tonumber(cash).."$", player, 0, 255, 0 ) 
        if isElement( Blips[marker] ) then 
            setBlipColor ( Blips[marker], 0, 255, 0, 255 ) 
            setMarkerColor (marker,0, 255, 0, 255 ) 
            outputDebugString("done") 
        end 
         
            local playerAccount = getPlayerAccount (player) 
            if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
            local totalStunts = getAccountData ( playerAccount, "totalStunts" ) or 0 
            local name = markerName 
            local rb,gb,bb,ab = getBlipColor (Blips[marker]) 
            local rm,gm,bm,am = getMarkerColor ( marker ) 
            local Det = toJSON({name,rb,gb,bb,ab,rm,gm,bm,am}) 
            setElementData (player, "entered.marker", true ) 
            setAccountData (playerAccount, "Details", Det ) 
            setAccountData(playerAccount, "totalStunts" , tonumber(totalStunts)+1) 
        end 
    end 
end 
  
-- I don't know why you need it ??? 
function leaveMar( leaveElement ) 
    if ( isElement ( leaveElement ) and getElementType ( leaveElement ) == "player" ) then 
        setElementData ( leaveElement, "entered.marker", false ) 
        outputChatBox("You failed the Stunt!", leaveElement, 255, 0, 0) 
    end 
end 
  
  
for i , v in pairs (Markers) do 
    HitMarker = createMarker ( v[2], v[3], v[4], "corona", 1.20, 255, 0, 0, 255 ) 
    Blips[HitMarker] = createBlipAttachedTo( HitMarker, 0 ) 
    details[HitMarker] = {v[1],v[5],v[6]} 
    addEventHandler( "onMarkerHit", HitMarker, allowedVehicles ) 
    addEventHandler ( "onMarkerLeave", HitMarker, leaveMar) 
end 
  
function stuntsFinished ( player ) 
    if isElement(player) then 
        local playerAccount = getPlayerAccount ( player ) 
        if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local count = getAccountData( playerAccount, "totalStunts" ) or 0 
        outputChatBox( "You have finished "..tonumber(count).."/512 Stunts", player, 0, 255, 0) 
        end 
    end 
end 
addCommandHandler("fstunts", stuntsFinished) 
  
  
function Load (_,cur) 
    local Det = getAccountData(cur,"Details") 
    if Det then 
        local marName,rb,gb,bb,ab,rm,gm,bm,am = unpack(fromJSON(Det)) 
        for i , mar in pairs (getElementsByType("marker")) do 
            local theTable = details[mar] 
            if (theTable) then       
            local name = details[mar][3] 
                if name == tostring(marName) then 
                    Entred[source] = mar 
                    setMarkerColor (mar,tonumber(rm),tonumber(gm),tonumber(bm),tonumber(am)) 
                end 
            end             
        end 
    end 
end 
addEventHandler("onPlayerLogin",root,Load) 

Edited by Guest
Link to comment

-- I don't know why you need it ???

function leaveMar( leaveElement ) 
    if ( isElement ( leaveElement ) and getElementType ( leaveElement ) == "player" ) then 
        setElementData ( leaveElement, "entered.marker", false ) 
        outputChatBox("You failed the Stunt!", leaveElement, 255, 0, 0) 
    end 
end 
  

Walid i use that thing because if a guy couldn't handle for 3 sec on stunt he fails the stunt and won't be rewarded.

Link to comment
Walid you've helped me before on that script too. :D

You are welcome anytime.

Walid i use that thing because if a guy couldn't handle for 3 sec on stunt he fails the stunt and won't be rewarded.

That's wrong as i can see you are just using "onMarkerLeave" event handler, there is no timer to check if the player stays inside the marker (3 sec). Anyways try to edit your code all what you need is :

isElementWithinMarker() -- after 3 second check if the player still inside the marker 

Edited by Guest
Link to comment
local Blips = {} 
local details = {} 
local Entred = {} 
  
local Markers = { 
{522, 1986, -1478.1, 21.5, 17.500, "Test Stunt #1"}, -- Marker 1 
{522, 1114, -1822, 33.5, 17.500, "Test Stunt #2"}, -- Marker 2 
{522, 776.8, -1036, 39.5, 9000, "Test Stunt #3"}, -- Marker 3 
{522, 1313, -1163, 41, 7500, "Test Stunt #4"}, -- Marker 4 
{522, 1404, -806, 85, 7500, "Test Stunt #5"}, -- Marker 5 
{522, 775.7, -1060.5, 33.2, 5000, "Test Stunt #6"}, -- Marker 6 
} 
  
function allowedVehicles( hitElement, matchingDimension ) 
    if matchingDimension and isElement(hitElement) and getElementType(hitElement) == "player" then 
        if isPedInVehicle ( hitElement ) then 
            local vehicle = getPedOccupiedVehicle ( hitElement ) 
            if vehicle then 
                if Entred[hitElement] == source then 
                    outputChatBox("Sorry you can't enter the marker twice" , hitElement,255,0,0) 
                    return 
                end 
                
                local theTable = details[source] 
                if (theTable) then       
                    local model, cash, name = details[source][1], details[source][2], details[source][3] 
                        if getElementModel ( vehicle ) == model then 
                            StuntComplete(hitElement,source,cash,name) -- You don't a timer here 
                            Entred[hitElement] = source 
                        else 
                        outputChatBox ( "You have entered in Stunt with wrong vehicle", hitElement, 255, 0, 0 ) 
                    end 
                end 
            end 
        end 
    end 
end 
  
  
function StuntComplete (player,marker,cash,markerName) 
    if isElement ( player ) then             
        givePlayerMoney ( player, tonumber(cash)) 
        outputChatBox ( "You have completed the Stunt and earned "..tonumber(cash).."$", player, 0, 255, 0 ) 
        if isElement( Blips[marker] ) then 
            setBlipColor ( Blips[marker], 0, 255, 0, 255 ) 
            setMarkerColor (marker,0, 255, 0, 255 ) 
            outputDebugString("done") 
        end 
        
            local playerAccount = getPlayerAccount (player) 
            if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
            local totalStunts = getAccountData ( playerAccount, "totalStunts" ) or 0 
            local name = markerName 
            local rb,gb,bb,ab = getBlipColor (Blips[marker]) 
            local rm,gm,bm,am = getMarkerColor ( marker ) 
            local Det = toJSON({name,rb,gb,bb,ab,rm,gm,bm,am}) 
            setElementData (player, "entered.marker", true ) 
            setAccountData (playerAccount, "Details", Det ) 
            setAccountData(playerAccount, "totalStunts" , tonumber(totalStunts)+1) 
        end 
    end 
end 
  
-- I don't know why you need it ??? 
function leaveMar( leaveElement ) 
    if ( isElement ( leaveElement ) and getElementType ( leaveElement ) == "player" ) then 
        setElementData ( leaveElement, "entered.marker", false ) 
        outputChatBox("You failed the Stunt!", leaveElement, 255, 0, 0) 
    end 
end 
  
  
for i , v in pairs (Markers) do 
    HitMarker = createMarker ( v[2], v[3], v[4], "corona", 1.20, 255, 0, 0, 255 ) 
    Blips[HitMarker] = createBlipAttachedTo( HitMarker, 0 ) 
    details[HitMarker] = {v[1],v[5],v[6]} 
    addEventHandler( "onMarkerHit", HitMarker, allowedVehicles ) 
    addEventHandler ( "onMarkerLeave", HitMarker, leaveMar) 
end 
  
function stuntsFinished ( player ) 
    if isElement(player) then 
        local playerAccount = getPlayerAccount ( player ) 
        if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local count = getAccountData( playerAccount, "totalStunts" ) or 0 
        outputChatBox( "You have finished "..tonumber(count).."/512 Stunts", player, 0, 255, 0) 
        end 
    end 
end 
addCommandHandler("fstunts", stuntsFinished) 
  
  
function Load (_,cur) 
    local Det = getAccountData(cur,"Details") 
    if Det then 
        local marName,rb,gb,bb,ab,rm,gm,bm,am = unpack(fromJSON(Det)) 
        for i , mar in pairs (getElementsByType("marker")) do 
            local theTable = details[mar] 
            if (theTable) then       
            local name = details[mar][3] 
                if name == tostring(marName) then 
                    Entred[source] = mar 
                    setMarkerColor (mar,tonumber(rm),tonumber(gm),tonumber(bm),tonumber(am)) 
                end 
            end             
        end 
    end 
end 
addEventHandler("onPlayerLogin",root,Load) 

This is whole script. Can you help me modify it, that i could add stunts which need timers and stunts which doesn't need timer? in vectors. I really want to learn that lua thing. But too hard to understand some complicated things as a beginner.

Link to comment
Walid, have you tested this on your local server? Nothing seems to be broken, but still nothing works, not any commandHandler not any outputted chatbox. :/ I got no errors but still nothing works :/

Working fine for me , already tested it.

Link to comment

Oh the problem... i put "client" in xml not server sorry. :D :D but can you help me modify its vector for timing too? "isElementWithinMarker() -- after 3 second check if the player still inside the marker" << This could work. But i don't want that every script had timing...

Link to comment
This is whole script. Can you help me modify it, that i could add stunts which need timers and stunts which doesn't need timer? in vectors. I really want to learn that lua thing. But too hard to understand some complicated things as a beginner.

1) It's very easy to do it just added the timer you want inside the table like this:

{522, 1986, -1478.1, 21.5, 17.500, "Test Stunt #1",Timer here}, -- Marker 1 

2) Added the timer to details table

details[HitMarker] = {v[1],v[5],v[6],v[7]} 

3) Then just check fi there is a timer when the player hits the marker :

local model, cash, name, timer = details[source][1], details[source][2], details[source][3], details[source][4] 
  
if timer then  
   -- setTimer here 
else 
   StuntComplete(hitElement,source,cash,name)  
end  

4) Also you need to check if the player still inside the marker with "isElementWithinMarker()" .

Link to comment
if timer then 

How that works?

i added the timer here

87e9b60896.png

so i'm checking if the timer exist or not.

if timer then -- if yes 
    setTimer(StuntComplete,tonumber(timer),1,hitElement,source,cash,name) 
else 
    StuntComplete(hitElement,source,cash,name) 
end  

Edited by Guest
Link to comment

Walid, sorry for so much questions but, I added timer as you said and it doesn't work. :/

local Blips = {} 
local details = {} 
local Entred = {} 
  
 --"Vector 1 = Vehicle ID", "Vector 2 - Vector 3 - Vector 4 = X, Y, Z Coordinates", "Vector 5 = Reward Money for completing Stunt", "Vector 6 = Name of the stunt", "Vector 7 = Needed time for completing the stunt" 
local Markers = { 
{522, 1986, -1478.1, 21.5, 17500, "Test Stunt #1", 3000}, -- Marker 1 
{522, 1114, -1822, 33.5, 17500, "Test Stunt #2", 0}, -- Marker 2 
{522, 776.8, -1036, 39.5, 9000, "Test Stunt #3", 0}, -- Marker 3 
{522, 1313, -1163, 41, 7500, "Test Stunt #4", 0}, -- Marker 4 
{522, 1404, -806, 85, 7500, "Test Stunt #5", 0}, -- Marker 5 
{522, 775.7, -1060.5, 33.2, 5000, "Test Stunt #6", 0}, -- Marker 6 
} 
  
function allowedVehicles( hitElement, matchingDimension ) 
    if matchingDimension and isElement(hitElement) and getElementType(hitElement) == "player" then 
        if isPedInVehicle ( hitElement ) then 
            local vehicle = getPedOccupiedVehicle ( hitElement ) 
            if vehicle then 
                if Entred[hitElement] == source then 
                    outputChatBox("Sorry you can't enter the marker twice" , hitElement,255,0,0) 
                    return 
                end 
                
                local theTable = details[source] 
                if (theTable) then       
                    local model, cash, name, timer = details[source][1], details[source][2], details[source][3], details[source][4] 
                        if getElementModel ( vehicle ) == model then 
                        if timer then 
                            StuntComplete(hitElement,source,cash,name) 
                            Entred[hitElement] = source 
                        else 
                        outputChatBox ( "You have entered in Stunt with wrong vehicle", hitElement, 255, 0, 0 ) 
                    end 
                end 
            end 
            end 
        end 
    end 
end 
  
  
function StuntComplete (player,marker,cash,markerName) 
    if isElement ( player ) then             
        givePlayerMoney ( player, tonumber(cash)) 
        outputChatBox ( "You have completed the Stunt and earned "..tonumber(cash).."$", player, 0, 255, 0 ) 
        if isElement( Blips[marker] ) then 
            setBlipColor ( Blips[marker], 0, 255, 0, 255 ) 
            setMarkerColor (marker,0, 255, 0, 255 ) 
            outputDebugString("done") 
        end 
        
            local playerAccount = getPlayerAccount (player) 
            if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
            local totalStunts = getAccountData ( playerAccount, "totalStunts" ) or 0 
            local name = markerName 
            local rb,gb,bb,ab = getBlipColor (Blips[marker]) 
            local rm,gm,bm,am = getMarkerColor ( marker ) 
            local Det = toJSON({name,rb,gb,bb,ab,rm,gm,bm,am}) 
            setAccountData (playerAccount, "entered.marker", true ) 
            setAccountData (playerAccount, "Details", Det ) 
            setAccountData(playerAccount, "totalStunts" , tonumber(totalStunts)+1) 
        end 
    end 
end 
  
  
function leaveMar( leaveElement ) 
    if ( isElement ( leaveElement ) and getElementType ( leaveElement ) == "player" ) then 
        setElementData ( leaveElement, "entered.marker", false ) 
        outputChatBox("You failed the Stunt!", leaveElement, 255, 0, 0) 
    end 
end 
  
  
for i , v in pairs (Markers) do 
    HitMarker = createMarker ( v[2], v[3], v[4], "corona", 1.20, 255, 0, 0, 255 ) 
    Blips[HitMarker] = createBlipAttachedTo( HitMarker, 0 ) 
    details[HitMarker] = {v[1],v[5],v[6],v[7]} 
    addEventHandler( "onMarkerHit", HitMarker, allowedVehicles ) 
    addEventHandler ( "onMarkerLeave", HitMarker, leaveMar) 
end 
  
function stuntsFinished ( player ) 
    if isElement(player) then 
        local playerAccount = getPlayerAccount ( player ) 
        if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local count = getAccountData( playerAccount, "totalStunts" ) or 0 
        outputChatBox( "You have finished "..tonumber(count).."/512 Stunts", player, 0, 255, 0) 
        end 
    end 
end 
addCommandHandler("fstunts", stuntsFinished) 
  
  
function Load (_,cur) 
    local Det = getAccountData(cur,"Details") 
    if Det then 
        local marName,rb,gb,bb,ab,rm,gm,bm,am = unpack(fromJSON(Det)) 
        for i , mar in pairs (getElementsByType("marker")) do 
            local theTable = details[mar] 
            if (theTable) then       
            local name = details[mar][3] 
                if name == tostring(marName) then 
                    Entred[source] = mar 
                    setMarkerColor (mar,tonumber(rm),tonumber(gm),tonumber(bm),tonumber(am)) 
                end 
            end             
        end 
    end 
end 
addEventHandler("onPlayerLogin",root,Load) 

Link to comment

+ After restarting script. #FinishedStunts is saved but not stunts. After restarting script i can take the stunt again. After relogging or reconnecting i see the same color as on the last activity on last account, but can take the stunt with another account as its new account.

Link to comment

So i just need to save the marker color and set it as AccountData not ElementData. I tried to do it but didn't work :/ and fix that after restarting script, accounts still save the stunts Finished. And these timers too. You are and will be the best if you help me do that :/

Link to comment

This is the latest full code atm.

local Blips = {} 
local details = {} 
local Entred = {} 
  
 --"Vector 1 = Vehicle ID", "Vector 2 - Vector 3 - Vector 4 = X, Y, Z Coordinates", "Vector 5 = Reward Money for completing Stunt", "Vector 6 = Name of the stunt", "Vector 7 = Needed time for completing the stunt" 
local Markers = { 
{522, 1986, -1478.1, 21.5, 17500, "Test Stunt #1", 3000}, -- Marker 1 
{522, 1114, -1822, 33.5, 17500, "Test Stunt #2", 0}, -- Marker 2 
{522, 776.8, -1036, 39.5, 9000, "Test Stunt #3", 0}, -- Marker 3 
{522, 1313, -1163, 41, 7500, "Test Stunt #4", 0}, -- Marker 4 
{522, 1404, -806, 85, 7500, "Test Stunt #5", 0}, -- Marker 5 
{522, 775.7, -1060.5, 33.2, 5000, "Test Stunt #6", 0}, -- Marker 6 
} 
  
function allowedVehicles( hitElement, matchingDimension ) 
    if matchingDimension and isElement(hitElement) and getElementType(hitElement) == "player" then 
        if isPedInVehicle ( hitElement ) then 
            local vehicle = getPedOccupiedVehicle ( hitElement ) 
            if vehicle then 
                if Entred[hitElement] == source then 
                    outputChatBox("Sorry you can't enter the marker twice" , hitElement,255,0,0) 
                    return 
                end 
                
                local theTable = details[source] 
                if (theTable) then       
                    local model, cash, name, timer = details[source][1], details[source][2], details[source][3], details[source][4] 
                        if getElementModel ( vehicle ) == model then 
                        if timer then 
                            StuntComplete(hitElement,source,cash,name) 
                            Entred[hitElement] = source 
                        else 
                        outputChatBox ( "You have entered in Stunt with wrong vehicle", hitElement, 255, 0, 0 ) 
                    end 
                end 
            end 
            end 
        end 
    end 
end 
  
  
function StuntComplete (player,marker,cash,markerName) 
    if isElement ( player ) then             
        givePlayerMoney ( player, tonumber(cash)) 
        outputChatBox ( "You have completed the Stunt and earned "..tonumber(cash).."$", player, 0, 255, 0 ) 
        if isElement( Blips[marker] ) then 
            setBlipColor ( Blips[marker], 0, 255, 0, 255 ) 
            setMarkerColor (marker,0, 255, 0, 255 ) 
            outputDebugString("done") 
        end 
        
            local playerAccount = getPlayerAccount (player) 
            if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
            local totalStunts = getAccountData ( playerAccount, "totalStunts" ) or 0 
            local name = markerName 
            local rb,gb,bb,ab = getBlipColor (Blips[marker]) 
            local rm,gm,bm,am = getMarkerColor ( marker ) 
            local Det = toJSON({name,rb,gb,bb,ab,rm,gm,bm,am}) 
            setAccountData (playerAccount, "entered.marker", Det ) 
            setAccountData (playerAccount, "Details", Det ) 
            setAccountData(playerAccount, "totalStunts" , tonumber(totalStunts)+1) 
        end 
    end 
end 
  
  
function leaveMar( leaveElement ) 
    if ( isElement ( leaveElement ) and getElementType ( leaveElement ) == "player" ) then 
        setElementData ( leaveElement, "entered.marker", false ) 
        outputChatBox("You failed the Stunt!", leaveElement, 255, 0, 0) 
    end 
end 
  
  
for i , v in pairs (Markers) do 
    HitMarker = createMarker ( v[2], v[3], v[4], "corona", 1.20, 255, 0, 0, 255 ) 
    Blips[HitMarker] = createBlipAttachedTo( HitMarker, 0 ) 
    details[HitMarker] = {v[1],v[5],v[6],v[7]} 
    addEventHandler( "onMarkerHit", HitMarker, allowedVehicles ) 
    addEventHandler ( "onMarkerLeave", HitMarker, leaveMar) 
end 
  
function stuntsFinished ( player ) 
    if isElement(player) then 
        local playerAccount = getPlayerAccount ( player ) 
        if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local count = getAccountData( playerAccount, "totalStunts" ) or 0 
        outputChatBox( "You have finished "..tonumber(count).."/512 Stunts", player, 0, 255, 0) 
        end 
    end 
end 
addCommandHandler("fstunts", stuntsFinished) 
  
  
function Load (_,cur) 
    local Det = getAccountData(cur,"Details") 
    if Det then 
        local marName,rb,gb,bb,ab,rm,gm,bm,am = unpack(fromJSON(Det)) 
        for i , mar in pairs (getElementsByType("marker")) do 
            local theTable = details[mar] 
            if (theTable) then       
            local name = details[mar][3] 
                if name == tostring(marName) then 
                    Entred[source] = mar 
                    setMarkerColor (mar,tonumber(rm),tonumber(gm),tonumber(bm),tonumber(am)) 
                end 
            end             
        end 
    end 
end 
addEventHandler("onPlayerLogin",root,Load) 

Link to comment

As far as i know double post is not allowed, anyways here is what you need.

-- Server side

local Blips = {} 
local details = {} 
local Entred = {} 
local timerTable = {} 
local detToSave = {} 
  
 --"Vector 1 = Vehicle ID", "Vector 2 - Vector 3 - Vector 4 = X, Y, Z Coordinates", "Vector 5 = Reward Money for completing Stunt", "Vector 6 = Name of the stunt", "Vector 7 = Needed time for completing the stunt" 
local Markers = { 
    {522, 1986, -1478.1, 21.5, 17500, "Test Stunt #1", 3000}, -- Marker 1 
    {522, 1114, -1822, 33.5, 17500, "Test Stunt #2", 1000}, -- Marker 2 
    {522, 776.8, -1036, 39.5, 9000, "Test Stunt #3", 1000}, -- Marker 3 
    {522, 1313, -1163, 41, 7500, "Test Stunt #4", 1000}, -- Marker 4 
    {522, 1404, -806, 85, 7500, "Test Stunt #5", 1000}, -- Marker 5 
    {522, 775.7, -1060.5, 33.2, 5000, "Test Stunt #6", 1000}, -- Marker 6 
} 
  
function allowedVehicles( hitElement, matchingDimension ) 
    if matchingDimension and isElement(hitElement) and getElementType(hitElement) == "player" then 
        if isPedInVehicle ( hitElement ) then 
            local vehicle = getPedOccupiedVehicle ( hitElement ) 
            if vehicle then 
                if Entred[source] then 
                    outputChatBox("Sorry you can't enter the marker twice" , hitElement,255,0,0) 
                    return 
                end 
                local theTable = details[source] 
                if (theTable) then       
                    local model, cash, name, timer = details[source][1], details[source][2], details[source][3], details[source][4] 
                        if getElementModel (vehicle) == model then 
                            if timer then 
                                if not isTimer(timerTable[hitElement]) then  
                                    timerTable[hitElement] = setTimer(StuntComplete,tonumber(timer),1,hitElement,source,cash,name) 
                                end  
                            else 
                                StuntComplete(hitElement,source,cash,name) 
                            end  
                        else 
                        outputChatBox ( "You have entered in Stunt with wrong vehicle", hitElement, 255, 0, 0 ) 
                    end 
                end 
            end 
        end 
    end 
end 
  
  
function StuntComplete (player,marker,cash,markerName) 
    if isElement ( player ) then   
        if isElementWithinMarker(player, marker) then 
            Entred[marker] = true 
            givePlayerMoney ( player, tonumber(cash)) 
            outputChatBox ( "You have completed the Stunt and earned "..tonumber(cash).."$", player, 0, 255, 0 ) 
            if isElement( Blips[marker] ) then 
                setBlipColor ( Blips[marker], 0, 255, 0, 255 ) 
                setMarkerColor (marker,0, 255, 0, 255 ) 
            end 
        
            local playerAccount = getPlayerAccount (player) 
            if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
            local totalStunts = getAccountData ( playerAccount, "totalStunts" ) or 0 
            local blipColor = Vector4(getBlipColor (Blips[marker])) 
            local markerColor = Vector4(getMarkerColor ( marker )) 
            detToSave[marker] = {markerName,blipColor.x,blipColor.y,blipColor.z,blipColor.w,markerColor.x,markerColor.y,markerColor.z,markerColor.w} 
            setAccountData (playerAccount, "Details",toJSON(detToSave)) 
            setAccountData(playerAccount, "totalStunts" , tonumber(totalStunts)+1) 
            end 
        else 
            outputChatBox("You failed the Stunt!", player, 255, 0, 0) 
        end 
    end 
end  
  
  
function leaveMar( leaveElement ) 
    if ( isElement ( leaveElement ) and getElementType ( leaveElement ) == "player" ) then 
        if isTimer(timerTable[leaveElement]) then 
            outputChatBox("You failed the Stunt!", leaveElement, 255, 0, 0) 
            killTimer(timerTable[leaveElement]) 
            timerTable[leaveElement] = nil 
        end  
    end 
end 
  
  
for i , v in pairs (Markers) do 
    HitMarker = createMarker ( v[2], v[3], v[4], "corona", 1.20, 255, 0, 0, 255 ) 
    Blips[HitMarker] = createBlipAttachedTo( HitMarker, 0 ) 
    details[HitMarker] = {v[1],v[5],v[6],v[7]} 
    addEventHandler( "onMarkerHit", HitMarker, allowedVehicles ) 
    addEventHandler ( "onMarkerLeave", HitMarker, leaveMar) 
end 
  
function stuntsFinished ( player ) 
    if isElement(player) then 
        local playerAccount = getPlayerAccount ( player ) 
        if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local count = getAccountData( playerAccount, "totalStunts" ) or 0 
        outputChatBox( "You have finished "..tonumber(count).."/512 Stunts", player, 0, 255, 0) 
        end 
    end 
end 
addCommandHandler("fstunts", stuntsFinished) 
  
  
function Load (_,cur,player) 
    if not player then  
        player = source 
    end  
    local Det = getAccountData(cur,"Details") 
    if Det then 
        for i,v in pairs(fromJSON (Det)) do 
            local marName,rb,gb,bb,ab,rm,gm,bm,am = unpack(v) 
                for i , mar in pairs (getElementsByType("marker")) do 
                local theTable = details[mar] 
                    if (theTable) then       
                        local name = details[mar][3] 
                        if name == tostring(marName) then 
                            Entred[mar] = true 
                            detToSave[mar] = {marName,rb,gb,bb,ab,rm,gm,bm,am} 
                            setMarkerColor (mar,tonumber(rm),tonumber(gm),tonumber(bm),tonumber(am)) 
                        if Blips[mar] then 
                            setBlipColor (Blips[mar],rb,gb,bb,ab) 
                        end  
                    end  
                end 
            end             
        end 
    end 
end 
addEventHandler("onPlayerLogin",root,Load) 
  
function loadOnResourceStart() 
    for i,v in pairs(getElementsByType("player")) do 
        local account = getPlayerAccount(v) 
        if account and not isGuestAccount(account) then  
            Load (_,account,v) 
        end  
    end  
end  
addEventHandler("onResourceStart",resourceRoot,loadOnResourceStart) 
  

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