Jump to content

infinity random marker


Recommended Posts

Hi

i want marker that can be on different positions ..

example

local Marker = createMarker ( 1431.1999511719, -1029.5, 22.5, "cylinder", 3, 255, 0, 0, 0 ) 
        addEventHandler("onClientMarkerHit", Marker ,function(hitPlayer) 
                if (hitPlayer == localPlayer) then 
                   destroyElement( Marker ) 

ok with destroyElement can't get the marker back

i don't want to create a new marker then new then new then new...

i want this marker if i hit it then it will be destroyed and show up on another position

just like if this Marker destroyed then return this action but on another position

using math.random

local Marker1 = createMarker ( math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165), "cylinder", 3, 255, 0, 0, 255 ) 
  

if i set it at 3 positions it gives me an error

but it only can be 2 positions

here's full code

addEvent("theMarkers", true) 
function theMarkers(Player) 
local Marker1 = createMarker ( math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165), "cylinder", 3, 255, 0, 0, 255 ) 
local Bblip1 = createBlip ( 0, 0, 0, 56, 3 ) 
        addEventHandler("onClientMarkerHit", Marker1,function(hitPlayer) 
        attachElements ( Marker1, Bblip1 ) 
            if isPedInVehicle ( localPlayer ) then 
                if (hitPlayer == localPlayer) then 
                    local randomly = math.random ( 5, 100 ) and math.random ( 50, 500 ) 
                        givePlayerMoney ( randomly ) 
                            outputChatBox(" You've got #00ff00$"..randomly.." #ffff00from the station",255,255,0, true) 
                                else 
                                    outputChatBox("you must be on your bus") 
                end 
            end 
        end 
        ) 
        addEventHandler("onClientMarkerLeave", Marker1,function(leavePlayer) 
            destroyElement ( Marker1 ) 
                destroyElement ( Bblip1 ) 
        end 
        ) 
end 
addEventHandler("theMarkers",getRootElement(),theMarkers) 

here if hit the marker it crashes the mta.exe ..

and the blip goes to another position ..

Link to comment

Dafuq. What about indentation?

addEvent( 'theMarkers', true ); 
  
local aElements = { } 
  
function theMarkers( thePlayer ) 
    --create markers 
    aElements['marker'] = createMarker( math.random( 1431, 1613 ), math.random( -1046, -1029 ), math.random( 22.5, 22.906229019165 ), 'cylinder', 3, 255, 0, 0, 255 ); 
    aElements['blip']   = createBlip( 0, 0, 0, 56, 3 ); 
     
    --add handlers 
    addEventHandler( 'onClientMarkerHit', aElements['marker'], fnOnMarkerHit ); 
    addEventHandler( 'onClientMarkerLeave', aElements['blip'], fnOnMarkerLeave ); 
end 
  
function fnOnMarkerHit( pPlayer ) 
    if( pPlayer == localPlayer ) then 
        bHasPassed = false; 
        if( isPedInVehicle( localPlayer ) ) then     
            attachElements( aElements['marker'], aElements['blip'] ); 
            local nRandom = math.random( 5, 100 ) + math.random( 50, 500 ); 
            givePlayerMoney( nRandom ); 
            outputChatBox( 'You have got #00FF00$' .. nRandom .. ' #FFFF00from the station!', 255, 255, 0, true ); 
            bHasPassed = true; 
        else 
            outputChatBox( 'You must be on your Bus!' ); 
        end 
    end 
end 
  
function fnOnMarkerLeave( ) 
    if( bHasPassed ) then 
        destroyElement( aElements['marker'] ); 
        destroyElement( aElements['blip'] ); 
    end 
end 
  

Fixed everything I saw.

Link to comment
Dafuq. What about indentation?
addEvent( 'theMarkers', true ); 
  
local aElements = { } 
  
function theMarkers( thePlayer ) 
    --create markers 
    aElements['marker'] = createMarker( math.random( 1431, 1613 ), math.random( -1046, -1029 ), math.random( 22.5, 22.906229019165 ), 'cylinder', 3, 255, 0, 0, 255 ); 
    aElements['blip']   = createBlip( 0, 0, 0, 56, 3 ); 
     
    --add handlers 
    addEventHandler( 'onClientMarkerHit', aElements['marker'], fnOnMarkerHit ); 
    addEventHandler( 'onClientMarkerLeave', aElements['blip'], fnOnMarkerLeave ); 
end 
  
function fnOnMarkerHit( pPlayer ) 
    if( pPlayer == localPlayer ) then 
        bHasPassed = false; 
        if( isPedInVehicle( localPlayer ) ) then     
            attachElements( aElements['marker'], aElements['blip'] ); 
            local nRandom = math.random( 5, 100 ) + math.random( 50, 500 ); 
            givePlayerMoney( nRandom ); 
            outputChatBox( 'You have got #00FF00$' .. nRandom .. ' #FFFF00from the station!', 255, 255, 0, true ); 
            bHasPassed = true; 
        else 
            outputChatBox( 'You must be on your Bus!' ); 
        end 
    end 
end 
  
function fnOnMarkerLeave( ) 
    if( bHasPassed ) then 
        destroyElement( aElements['marker'] ); 
        destroyElement( aElements['blip'] ); 
    end 
end 
  

Fixed everything I saw.

well, it's not fixed lol

i don't see the marker or the blip

Link to comment

I want if i hit the " RANDOM " marker .. it simply will be disappeared .. so .. i won't create a new markers i just want this marker show up on random positions if i hit it .. it will be created again then again but on random positions you understand me ?

Link to comment

try this:

addEvent("theMarkers", true) 
addEventHandler("theMarkers",root,function()--there is no need for the first arguement 
    local Marker1 = createMarker ( math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165), "cylinder", 3, 255, 0, 0, 255 ) 
    local Bblip1 = createBlip ( 0, 0, 0, 56, 3 ) 
    attachElements ( Marker1, Bblip1 ) --attach elements outside of the event 
    addEventHandler("onClientMarkerHit", Marker1,function(hitPlayer) 
        if (hitPlayer == localPlayer) then --check if the hitPlayer is localPlayer first 
            if isPedInVehicle ( hitPlayer ) then 
                local randomly = math.random ( 5, 100 ) and math.random ( 50, 500 ) 
                givePlayerMoney ( randomly ) 
                outputChatBox(" You've got #00ff00$"..randomly.." #ffff00from the station",255,255,0, true) 
                setElementPosition(Marker1,math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165)) --set Markers Position 
            else 
                outputChatBox("you must be on your bus") 
            end 
        end 
    end) 
end) 

Link to comment

Thanks alot Jaysds

But if hit this marker which on the random position

it gives me alot of money

like this

you've got ... from the station

you've got ... from the station

you've got ... from the station

you've got ... from the station

you've got ... from the station

it also show up on 1 position only

should i use destroyElement onClientMarkerLeave or what ?

Link to comment

what's this suppose to be?

local randomly = math.random ( 5, 100 ) and math.random ( 50, 500 ) 

How much value's do you expect in it?

once both of them are done, it'll look like this: 550 or 100500.

BTW, when is this event triggered "theMarkers"?

Link to comment

i did like this

addEvent("theMarkers", true) 
    addEventHandler("theMarkers",root,function()--there is no need for the first arguement 
        local Marker1 = createMarker ( math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165), "cylinder", 3, 255, 0, 0, 255 ) 
        local Bblip1 = createBlip ( 0, 0, 0, 56, 3 ) 
        attachElements ( Marker1, Bblip1 ) --attach elements outside of the event 
        addEventHandler("onClientMarkerHit", Marker1,function(hitPlayer) 
            if (hitPlayer == localPlayer) then --check if the hitPlayer is localPlayer first 
                if isPedInVehicle ( hitPlayer ) then 
                    local randomly = math.random ( 5, 100 ) and math.random ( 50, 500 ) 
                    givePlayerMoney ( randomly ) 
                    outputChatBox(" You've got #00ff00$"..randomly.." #ffff00from the station",255,255,0, true) 
                    else 
                    outputChatBox("you must be in your bus") 
                    addEventHandler("onClientMarkerLeave", Marker1,function(leavePlayer) 
                    destroyElement ( Marker1 ) 
                    setElementPosition(Marker1,math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165)) --set Markers Position 
                    end) 
                end 
            end 
        end) 
    end) 

the outPutChatBox problem was fixed but when i hit this marker it won't disappear and show up on another position

Link to comment

wait i show all the code

server side

local blip = createBlip ( 0, 0, 0, 0, 3 ) 
local BusJobMarker = createMarker ( 1620.2777099609, -1041.3696289063, 22.8984375, "cylinder", 2, 255, 0, 0, 255 ) 
local busteam = createTeam ( "Bus drivers", 255, 255, 0 ) 
  
    function attachblipwith() 
        attachElements ( blip, BusJobMarker, 0, 0, 0 ) 
    end 
addEventHandler("onResourceStart", getRootElement(), attachblipwith) 
  
    function showWindow(player) 
            if not isPedInVehicle(player) then 
                triggerClientEvent(player,"Showbusjobwindow", player) 
            end 
    end 
addEventHandler("onMarkerHit", getRootElement(), showWindow) 
  
addEvent("StartBusJob", true) 
  
buses = { } 
      
    function StartBusJob ( ) 
        setPlayerTeam ( source, busteam ) 
        local gX, gY, gZ = getElementPosition ( source ) 
        if ( isElement ( buses [ source ] ) ) then 
            destroyElement ( buses [ source ] ) 
        end 
        buses [ source ] = createVehicle ( 431, gX, gY, gZ ) 
        setTimer ( warpPedIntoVehicle, 200, 1, source, buses [ source ]) 
        setPedSkin ( source, 253 ) 
        triggerClientEvent("theMarkers", getRootElement(), buses) 
    end 
    addEventHandler ( "StartBusJob", root, StartBusJob ) 

" GUI client side "

addEvent("Showbusjobwindow", true) 
        function Showbusjobwindow() 
        guiSetVisible(GUIEditor_Window[1], true) 
        showCursor(true) 
        guiSetInputEnabled(false) 
        end 
addEventHandler("Showbusjobwindow",getRootElement(),Showbusjobwindow) 
  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Memo = {} 
GUIEditor_Grid = {} 
GUIEditor_Window[1] = guiCreateWindow(318,268,494,200,"[LSR]BusJob",false) 
guiSetAlpha(GUIEditor_Window[1],1) 
GUIEditor_Button[1] = guiCreateButton(162,144,144,36,"Start Job",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(9,158,71,30,"EXIT",false,GUIEditor_Window[1]) 
GUIEditor_Button[3] = guiCreateButton(438,26,41,32,"?",false,GUIEditor_Window[1]) 
GUIEditor_Memo[1] = guiCreateMemo(81,84,339,54,"============|Bus Job|=============\nThe objective of this Job and passenger movement between the positions and the streets must be moved from position to another this Job does not have a fixed salary is dependent on your effort to work\n============|Bus Job|=============t",false,GUIEditor_Window[1]) 
guiMemoSetReadOnly(GUIEditor_Memo[1],true) 
guiSetVisible( GUIEditor_Window[1], false ) 
guiSetVisible( GUIEditor_Memo[1], false ) 
  
    function exiting() 
        if ( source == GUIEditor_Button[2] ) then 
            guiSetVisible ( GUIEditor_Window[1], false ) 
                showCursor( false ) 
                    guiSetInputEnabled( false ) 
        end 
    end 
addEventHandler("onClientGUIClick", getRootElement(), exiting) 
  
    function showTheMemo() 
        if ( source == GUIEditor_Button[3] ) then 
            guiSetVisible ( GUIEditor_Memo[1], true ) 
        end 
    end 
addEventHandler("onClientGUIClick", getRootElement(), showTheMemo) 
  
    function startTheJob() 
        if ( source == GUIEditor_Button[1] ) then 
            triggerServerEvent ("StartBusJob", localPlayer, player) 
                guiSetVisible ( GUIEditor_Window[1], false ) 
                    showCursor( false ) 
                        guiSetInputEnabled( false ) 
            end 
        end 
addEventHandler("onClientGUIClick", getRootElement(), startTheJob) 

and finally client side

addEvent("theMarkers", true) 
    addEventHandler("theMarkers",root,function() 
        local Marker1 = createMarker ( math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165), "cylinder", 3, 255, 0, 0, 255 ) 
        local Bblip1 = createBlip ( 0, 0, 0, 56, 3 ) 
        attachElements ( Marker1, Bblip1 ) --attach elements outside of the event 
        addEventHandler("onClientMarkerHit", Marker1,function(hitPlayer) 
            if (hitPlayer == localPlayer) then --check if the hitPlayer is localPlayer first 
                if isPedInVehicle ( hitPlayer ) then 
                    local randomly = math.random ( 5, 100 ) 
                    givePlayerMoney ( randomly ) 
                    outputChatBox(" You've got #00ff00$"..randomly.." #ffff00from the station",255,255,0, true) 
                    else 
                    outputChatBox("you must be in your bus") 
                    addEventHandler("onClientMarkerLeave", Marker1,function(leavePlayer) 
                    destroyElement ( Marker1 ) 
                    setElementPosition(Marker1,math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165)) --set Markers Position 
                    end) 
                end 
            end 
        end) 
    end) 

this is bus job .. if i created a counted markers .. shall i create it every time .. ? or it must be "infinity" marker

but i have an idea

ok if i created the markers ..

is there any thing that return the action i mean if hit the final marker the first marker will show up etc etc etc ..

Link to comment

ok, try this,

Server-side:

local blip = createBlip ( 0, 0, 0, 0, 3 ) 
local BusJobMarker = createMarker ( 1620.2777099609, -1041.3696289063, 22.8984375, "cylinder", 2, 255, 0, 0, 255 ) 
attachElements (blip, BusJobMarker) 
  
local busteam = createTeam ( "Bus drivers", 255, 255, 0 ) 
  
addEventHandler("onMarkerHit",BusJobMarker,function(player) 
    if not isPedInVehicle(player) then 
        triggerClientEvent(player,"Showbusjobwindow", player) 
    end 
end) 
  
buses = { } 
addEvent("StartBusJob", true) 
addEventHandler ( "StartBusJob",root,function() 
    setPlayerTeam ( client, busteam ) 
    local gX, gY, gZ = getElementPosition ( client ) 
    if ( isElement ( buses [ client ] ) ) then 
        destroyElement ( buses [ client ] ) 
    end 
    buses [ client ] = createVehicle ( 431, gX, gY, gZ ) 
    setElementModel( client, 253 ) 
    setTimer ( warpPedIntoVehicle, 1000, 1, client, buses [ client ]) 
    triggerClientEvent(client,"theMarkers",client, buses[client]) 
end) 

Client-side:

GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Memo = {} 
GUIEditor_Grid = {} 
GUIEditor_Window[1] = guiCreateWindow(318,268,494,200,"[LSR]BusJob",false) 
guiSetAlpha(GUIEditor_Window[1],1) 
GUIEditor_Button[1] = guiCreateButton(162,144,144,36,"Start Job",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(9,158,71,30,"EXIT",false,GUIEditor_Window[1]) 
GUIEditor_Button[3] = guiCreateButton(438,26,41,32,"?",false,GUIEditor_Window[1]) 
GUIEditor_Memo[1] = guiCreateMemo(81,84,339,54,"============|Bus Job|=============\nThe objective of this Job and passenger movement between the positions and the streets must be moved from position to another this Job does not have a fixed salary is dependent on your effort to work\n============|Bus Job|=============t",false,GUIEditor_Window[1]) 
guiMemoSetReadOnly(GUIEditor_Memo[1],true) 
guiSetVisible( GUIEditor_Window[1], false ) 
guiSetVisible( GUIEditor_Memo[1], false ) 
  
addEvent("Showbusjobwindow", true) 
addEventHandler("Showbusjobwindow",root,function() 
    guiSetVisible(GUIEditor_Window[1], true) 
    showCursor(true) 
    guiSetInputEnabled(true) 
end) 
  
addEventHandler("onClientGUIClick",guiRoot,function() 
    if ( source == GUIEditor_Button[1] ) then 
        triggerServerEvent ("StartBusJob", localPlayer) 
        guiSetVisible ( GUIEditor_Window[1], false ) 
        showCursor( false ) 
        guiSetInputEnabled( false ) 
    elseif ( source == GUIEditor_Button[2] ) then 
        guiSetVisible ( GUIEditor_Window[1], false ) 
        showCursor( false ) 
        guiSetInputEnabled( false ) 
    elseif ( source == GUIEditor_Button[3] ) then 
        guiSetVisible ( GUIEditor_Memo[1], true ) 
    end 
end,true) --forgot the bool at the end 
  
addEvent("theMarkers", true) 
addEventHandler("theMarkers",root,function(bus) 
    local Marker1 = createMarker ( math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165), "cylinder", 3, 255, 0, 0, 255 ) 
    local Bblip1 = createBlip (0, 0, 0, 56, 3 ) 
    attachElements ( Marker1, Bblip1 ) --attach elements outside of the event 
    addEventHandler("onClientMarkerHit", Marker1,function(hitPlayer) 
        if (hitPlayer == localPlayer) then --check if the hitPlayer is localPlayer first 
            if isPedInVehicle ( hitPlayer ) then 
                if getElementModel(getPedOccupiedVehicle(hitPlayer))~= 431 then outputChatBox("You are not in the Bus, please get a bus.") return end 
                local randomly = math.random ( 5, 100 ) 
                givePlayerMoney ( randomly ) 
                outputChatBox(" You've got #00ff00$"..randomly.." #ffff00from the station",255,255,0, true) 
            else 
                outputChatBox("you must be in your bus") 
            end 
        end 
    end) 
    addEventHandler("onClientMarkerLeave", Marker1,function(leavePlayer) 
        setElementPosition(Marker1,math.random (1431,1613), math.random (-1046,-1029), math.random (22.5,22.906229019165)) --set Markers Position 
    end) 
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...