Jump to content

[HELP] onClientMarkerHit with takePlayerMoney


Recommended Posts

Hi, Im trying to make a script in which - when a client hits a marker, $500 will be deducted from his money. The code I wrote is not working and I need help:

  
marker_00 = createMarker(1178,-1317,14,"cylinder",1,255,255,150) 
marker_01 = createMarker(1252,329,20,"cylinder",1,255,255,150) 
marker_02 = createMarker(-312,1052,20.5,"cylinder",1,255,255,150) 
marker_03 = createMarker(1600,1820,11,"cylinder",1,255,255,150) 
marker_04 = createMarker(-2667,636,14.5,"cylinder",1,255,255,150) 
marker_05 = createMarker(2030,-1405,17.5,"cylinder",1,255,255,150) 
marker_06 = createMarker(-1520,2520,56,"cylinder",1,255,255,150) 
marker_07 = createMarker(-2190,-2300,30.5,"cylinder",1,255,255,150) 
marker_08 = createMarker(2026,-1408,16,"cylinder",1,255,255,150) 
  
function takeHisMoney(thePlayer) 
    takePlayerMoney (thePlayer, 500) 
end 
  
addEventHandler("onClientMarkerHit", marker_00,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_01,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_02,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_03,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_04,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_05,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_06,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_07,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_08,takeHisMoney) 
  

Link to comment

try:

client

  
marker_00 = createMarker(1178,-1317,14,"cylinder",1,255,255,150) 
marker_01 = createMarker(1252,329,20,"cylinder",1,255,255,150) 
marker_02 = createMarker(-312,1052,20.5,"cylinder",1,255,255,150) 
marker_03 = createMarker(1600,1820,11,"cylinder",1,255,255,150) 
marker_04 = createMarker(-2667,636,14.5,"cylinder",1,255,255,150) 
marker_05 = createMarker(2030,-1405,17.5,"cylinder",1,255,255,150) 
marker_06 = createMarker(-1520,2520,56,"cylinder",1,255,255,150) 
marker_07 = createMarker(-2190,-2300,30.5,"cylinder",1,255,255,150) 
marker_08 = createMarker(2026,-1408,16,"cylinder",1,255,255,150) 
  
function takeHisMoney(thePlayer) 
triggerServerEvent("ReduceMoneyTrigger",thePlayer) 
end 
  
addEventHandler("onClientMarkerHit", marker_00,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_01,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_02,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_03,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_04,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_05,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_06,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_07,takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_08,takeHisMoney) 
  

server

addEvent("ReduceMoneyTrigger",true) 
addEventHandler("ReduceMoneyTrigger",root, 
function() 
local money = getPlayerMoney(client) 
if(money>=500)then 
takePlayerMoney(client,500) 
else 
outputChatBox("No enought money",client) 
end 
end) 
  

Link to comment

but here is better(i think)

client

  
marker_00 = createMarker(1178,-1317,14,"cylinder",1,255,255,150) 
marker_01 = createMarker(1252,329,20,"cylinder",1,255,255,150) 
marker_02 = createMarker(-312,1052,20.5,"cylinder",1,255,255,150) 
marker_03 = createMarker(1600,1820,11,"cylinder",1,255,255,150) 
marker_04 = createMarker(-2667,636,14.5,"cylinder",1,255,255,150) 
marker_05 = createMarker(2030,-1405,17.5,"cylinder",1,255,255,150) 
marker_06 = createMarker(-1520,2520,56,"cylinder",1,255,255,150) 
marker_07 = createMarker(-2190,-2300,30.5,"cylinder",1,255,255,150) 
marker_08 = createMarker(2026,-1408,16,"cylinder",1,255,255,150) 
  
function takeHisMoney(thePlayer) 
if(source==marker_00) or(source==marker_01)or (source==marker_02)or(source==marker_03)or(source==marker_04) 
or(source==marker_05) or (source==marker_06) or (source==marker_07)or(source==marker_08) then 
triggerServerEvent("ReduceMoneyTrigger",thePlayer) 
end 
end 
addEventHandler("onClientMarkerHit", root,takeHisMoney) 
  

Link to comment
addEvent("ReduceMoneyTrigger",true) 
addEventHandler("ReduceMoneyTrigger",root, 
function() 
local money = getPlayerMoney(client) 
if(money>=500)then 
takePlayerMoney(client,500) 
setPedStat(client,24,999) 
setElementHealth(client,200) 
else 
outputChatBox("No enought money",client) 
end 
end) 

Link to comment

I think that you should actually use this for the function/event handler:

function takeHisMoney(thePlayer) 
    if ( thePlayer == localPlayre ) then 
        triggerServerEvent("ReduceMoneyTrigger",thePlayer) 
    end 
end 
addEventHandler("onClientMarkerHit", marker_00, takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_01, takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_02, takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_03, takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_04, takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_05, takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_06, takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_07, takeHisMoney) 
addEventHandler("onClientMarkerHit", marker_08, takeHisMoney) 

You forgot to check if the player is the localPlayer.

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