Strikadilla Posted March 8, 2023 Share Posted March 8, 2023 Hello friends, sorry for my bad english... I have problem, i have Drug-job script for RolePlay server, it works on hitmarkers, when i hit marker, it dissapears for all players, how to make it for every player to work separately? I know that i need to fix it by putting LocalPlayer somewhere, but where, started scripting 3 days ago. Can someone fix it so for every player hitmarkers work separately? Server side: local Pickup_Seed = createMarker(-1062.55, -1084.62, 128.21, "cylinder", 1.5, 0, 255, 0, 100) local Pickup_Planting = createMarker(-1089.47, -1090.35, 128.21, "cylinder", 1.5, 0, 255, 0, 100) local Pickup_Preparation = createMarker(-1064.33, -1095.58, 128.21, "cylinder", 1.5, 0, 255, 0, 100) local Pickup_Buyer = createMarker( -1072.6064453125, -1070.298828125, 129.21875, "cylinder", 1.5, 0, 255, 0, 100) local PED_Buyer = createPed(29, -1072.7197265625, -1068.4462890625, 129.21875) setElementRotation(PED_Buyer, 180, 180, 180) setElementFrozen(PED_Buyer, true) setMarkerSize(Pickup_Planting, 0) setMarkerSize(Pickup_Preparation, 0) function MassageJoinPickup(source) triggerClientEvent(source, "EnableMassagePickup", getRootElement()) end addEventHandler("onMarkerHit", Pickup_Seed, MassageJoinPickup) function MassageLeavePickup(source) triggerClientEvent(source, "EnableMassagePickup", getRootElement()) end addEventHandler("onMarkerLeave", Pickup_Seed, MassageLeavePickup) function MassageJoinPickupPlanting(source) triggerClientEvent(source, "EnableMassagePickup", getRootElement()) end addEventHandler("onMarkerHit", Pickup_Planting, MassageJoinPickupPlanting) function MassageLeavePickupPlanting(source) triggerClientEvent(source, "EnableMassagePickup", getRootElement()) end addEventHandler("onMarkerLeave", Pickup_Planting, MassageLeavePickupPlanting) function MassageJoinPickupPreparation(source) triggerClientEvent(source, "EnableMassagePickup", getRootElement()) end addEventHandler("onMarkerHit", Pickup_Preparation, MassageJoinPickupPreparation) function MassageLeavePickupPreparation(source) triggerClientEvent(source, "EnableMassagePickup", getRootElement()) end addEventHandler("onMarkerLeave", Pickup_Preparation, MassageLeavePickupPreparation) function MassageJoinPickupBuyer(source) triggerClientEvent(source, "EnableMassagePickup", getRootElement()) end addEventHandler("onMarkerHit", Pickup_Buyer, MassageJoinPickupBuyer) function MassageLeavePickupBuyer(source) triggerClientEvent(source, "EnableMassagePickup", getRootElement()) end addEventHandler("onMarkerLeave", Pickup_Buyer, MassageLeavePickupBuyer) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function Seed(source) if isElementWithinMarker(source, Pickup_Seed) then if getElementData(source, "GameLight:Seed") == false then setElementFrozen(source, true) setPedAnimation(source, "bar", "barcustom_get", 5000, true, false, false, false) triggerClientEvent(source, "EnableTimer3D_1", getRootElement()) setTimer(function() triggerClientEvent(localPlayer, source, "Remover_1", getRootElement()) end, 5000, 1) setTimer(function() setElementData(source, "GameLight:Seed", true) setElementFrozen(source, false) outputChatBox("#0000ff[Narkotikas] #ffffffTu savāci sēklu, ej iestādi to.", source, 255, 255, 255, true) setMarkerSize(Pickup_Planting, 1.5) setMarkerSize(Pickup_Seed, 0) end, 5000, 1) else outputChatBox("#0000ff[Narkotikas] #ffffffTev ir sēkla, iestādi to sākumā.", source, 255, 255, 255, true) end end end function StartBindKeySeed() for i, v in ipairs(getElementsByType("player")) do bindKey ( v, "h", "down", Seed ) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), StartBindKeySeed) function JoinBindKeySeed() bindKey ( source, "h", "down", Seed ) end addEventHandler("onPlayerJoin", getRootElement(), JoinBindKeySeed) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function Planting(source) if isElementWithinMarker(source, Pickup_Planting) then if getElementData(source, "GameLight:Seed") == true then triggerClientEvent(source, "EnableTimer3D_2", getRootElement()) setTimer(function() triggerClientEvent(source, "Remover_2", getRootElement()) end, 30000, 1) setElementFrozen(source, true) Plant = createObject(675, -1089.47, -1090.35, 128.21) setPedAnimation(source, "BOMBER", "BOM_Plant", 30000, true, false, false, false) setTimer(function() setElementData(source, "GameLight:Seed", false) outputChatBox("#0000ff[Narkotikas] #ffffffIestādi sēklu un pagaidi kamēr tā izaugs", source, 255, 255, 255, true) setTimer(function() destroyElement(Plant) Drugs = createObject(3409, -1089.47, -1090.35, 128.21) outputChatBox("#0000ff[Narkotikas] #ffffffSēkla izauga, tagad savāc ražu.", source, 255, 255, 255, true) setTimer(function() destroyElement(Drugs) setElementFrozen(source, false) setElementData(source, "GameLight:Drugs", true) setMarkerSize(Pickup_Planting, 0) setMarkerSize(Pickup_Preparation, 1.5) outputChatBox("#0000ff[Narkotikas] #ffffffTu savāci ražu, ej pie galda.", source, 255, 255, 255, true) end, 5000, 1) end, 20000, 1) end, 5000, 1) else outputChatBox("#0000ff[Narkotikas] #ffffffTev nav sēklas, sākumā paņem to.", source, 255, 255, 255, true) end end end function StartBindKeyPlanting() for i, v in ipairs(getElementsByType("player")) do bindKey ( v, "h", "down", Planting ) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), StartBindKeyPlanting) function JoinBindKeyPlanting() bindKey ( source, "h", "down", Planting ) end addEventHandler("onPlayerJoin", getRootElement(), JoinBindKeyPlanting) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function Preparation(source) if isElementWithinMarker(source, Pickup_Preparation) then if getElementData(source, "GameLight:Drugs") == true then setElementFrozen(source, true) setPedAnimation(source, "bar", "barcustom_get", 30000, true, false, false, false) outputChatBox("#0000ff[Narkotikas] #ffffffTu sasmalcini lapu un sapako to.", source, 255, 255, 255, true) triggerClientEvent(source, "EnableTimer3D_2", getRootElement()) setTimer(function() triggerClientEvent(source, "Remover_2", getRootElement()) end, 30000, 1) setTimer(function() setElementData(source, "GameLight:Drugs", false) setElementFrozen(source, false) setElementData(source, "GameLight:DrugsSell", true) setMarkerSize(Pickup_Preparation, 0) outputChatBox("#0000ff[Narkotikas] #ffffffNarkotikas ir gatavas, nes tās pie pircēja.", source, 255, 255, 255, true) end, 30000, 1) else outputChatBox("#0000ff[Narkotikas] #ffffffTev nav narkotiku ko sagatavot.", source, 255, 255, 255, true) end end end function StartBindKeyPreparation() for i, v in ipairs(getElementsByType("player")) do bindKey ( v, "h", "down", Preparation ) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), StartBindKeyPreparation) function JoinBindKeyPreparation() bindKey ( source, "h", "down", Preparation ) end addEventHandler("onPlayerJoin", getRootElement(), JoinBindKeyPreparation) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function givemaitmoney() exports.global:giveMoney(source, aleatorio) end addEvent("vz_GiveMoney", true) addEventHandler("vz_GiveMoney", root, givemaitmoney) function Buyer(source, thePlayer) if isElementWithinMarker(source, Pickup_Buyer) then if getElementData(source, "GameLight:DrugsSell") == true then setElementData(source, "GameLight:DrugsSell", false) local AmountMoneySell = math.random(1, 2) exports.global:giveMoney(source, AmountMoneySell) setMarkerSize(Pickup_Seed, 1.5) outputChatBox("#0000ff[Narkotikas] #ffffffTu ieguvi: $"..AmountMoneySell.."", source, 255, 255, 255, true) else outputChatBox("#0000ff[Narkotikas] #ffffffTev nav narkotiku ko pārdot.", source, 255, 255, 255, true) end end end function StartBindKeyBuyer() for i, v in ipairs(getElementsByType("player")) do bindKey ( v, "h", "down", Buyer ) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), StartBindKeyBuyer) function JoinBindKeyBuyer() bindKey ( source, "h", "down", Buyer ) end addEventHandler("onPlayerJoin", getRootElement(), JoinBindKeyBuyer) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Client side: local screenW, screenH = guiGetScreenSize() local x, y = (screenW/1366), (screenH/768) local screen = {guiGetScreenSize()} local box = {480,35} local pos = {screen[1]/2 -box[1]/2,screen[2]/1.2 -box[2]/2+50} local Font = dxCreateFont("Files/Font.ttf", 12) local ActiveMassageMarker = false function ActiveMassageInPickup() local KeyStart = "h" dxDrawText("Uzspied ["..KeyStart.."] pogu.", (screenW * 0.4180) - 1, (screenH * 0.8500) - 1, (screenW * 0.5820) - 1, (screenH * 1.0099) - 1, tocolor(0, 0, 0, 255), 1.15, Font, "center", "center", false, false, false, true, false) dxDrawText("Uzspied ["..KeyStart.."] pogu.", (screenW * 0.4180) + 1, (screenH * 0.8500) - 1, (screenW * 0.5820) + 1, (screenH * 1.0099) - 1, tocolor(0, 0, 0, 255), 1.15, Font, "center", "center", false, false, false, true, false) dxDrawText("Uzspied ["..KeyStart.."] pogu.", (screenW * 0.4180) - 1, (screenH * 0.8500) + 1, (screenW * 0.5820) - 1, (screenH * 1.0099) + 1, tocolor(0, 0, 0, 255), 1.15, Font, "center", "center", false, false, false, true, false) dxDrawText("Uzspied ["..KeyStart.."] pogu.", (screenW * 0.4180) + 1, (screenH * 0.8500) + 1, (screenW * 0.5820) + 1, (screenH * 1.0099) + 1, tocolor(0, 0, 0, 255), 1.15, Font, "center", "center", false, false, false, true, false) dxDrawText("#ffffffUzspied [#ff0000"..KeyStart.."#ffffff] pogu.", screenW * 0.4180, screenH * 0.8500, screenW * 0.5820, screenH * 1.0099, tocolor(255, 255, 255, 255), 1.15, Font, "center", "center", false, false, false, true, false) end function EnableMassagePickup() if ActiveMassageMarker == false then addEventHandler("onClientRender", root, ActiveMassageInPickup) ActiveMassageMarker = true else removeEventHandler("onClientRender", root, ActiveMassageInPickup) ActiveMassageMarker = false end end addEvent("EnableMassagePickup", true) addEventHandler("EnableMassagePickup", getRootElement(), EnableMassagePickup) function math.percent(percent,maxvalue) if tonumber(percent) and tonumber(maxvalue) then return (maxvalue*percent)/100 end return false end function math.percent2(percent,maxvalue) if tonumber(percent) and tonumber(maxvalue) then return (maxvalue*percent)/100 end return false end function Percent() if (isTimer(Timer)) then m = getTimerDetails(Timer) m = m/1000 mat = math.percent(m, 30) return mat else return 0 end end function Timer3D_1() if (isTimer(Timer)) then local percent = Percent() local percent = percent * 67 local evr = math.percent2(percent, x*340) dxDrawRectangle(x*510, y*680, x*340, y*20, tocolor (0, 0, 0, 150)) dxDrawRectangle(x*510, y*680, x*340-evr, y*20, tocolor (0, 0, 139, 255)) dxDrawText("Uzgaidi... [5 Sekundes]", (screenW * 0.4180) - 1, (screenH * 0.7950) - 1, (screenW * 0.5820) - 1, (screenH * 1.0099) - 1, tocolor(255, 255, 255, 255), 1.15, Font, "center", "center", false, false, false, true, false) end end function Timer3D_2() if (isTimer(Timer)) then local percent = Percent() local percent = percent * 11 local evr = math.percent2(percent, x*340) dxDrawRectangle(x*510, y*680, x*340, y*20, tocolor (0, 0, 0, 150)) dxDrawRectangle(x*510, y*680, x*340-evr, y*20, tocolor (0, 0, 139, 255)) dxDrawText("Uzgaidi... [30 Sekundes]", (screenW * 0.4180) - 1, (screenH * 0.7950) - 1, (screenW * 0.5820) - 1, (screenH * 1.0099) - 1, tocolor(255, 255, 255, 255), 1.15, Font, "center", "center", false, false, false, true, false) end end function EnableTimer3D_1() Timer = setTimer(function() end, 5000, 1) removeEventHandler("onClientRender", getRootElement(), Timer3D_1) addEventHandler("onClientRender", getRootElement(), Timer3D_1) end addEvent("EnableTimer3D_1", true) addEventHandler("EnableTimer3D_1", getRootElement(), EnableTimer3D_1) function EnableTimer3D_2() Timer = setTimer(function() end, 30000, 1) removeEventHandler("onClientRender", getRootElement(), Timer3D_2) addEventHandler("onClientRender", getRootElement(), Timer3D_2) end addEvent("EnableTimer3D_2", true) addEventHandler("EnableTimer3D_2", getRootElement(), EnableTimer3D_2) function Remover_1() removeEventHandler("onClientRender", getRootElement(), Timer3D_1) end addEvent("Remover_1", true) addEventHandler("Remover_1", getRootElement(), Remover_1) function Remover_2() removeEventHandler("onClientRender", getRootElement(), Timer3D_2) end addEvent("Remover_2", true) addEventHandler("Remover_2", getRootElement(), Remover_2) function RestartDrugs() ActiveMassageMarker = false removeEventHandler("onClientRender", getRootElement(), Timer3D_1) removeEventHandler("onClientRender", getRootElement(), Timer3D_2) end addEventHandler("onClientResourceStart", getRootElement(), RestartDrugs) Link to comment
Molvine Posted March 8, 2023 Share Posted March 8, 2023 (edited) The localPlayer variable does not exist on the Server-side. LocalPlayer specifies the player element on the Client-side. I found some obvious bugs in your code: In the Seed function, you are trying to specify localPlayer as the rootElement, and you are violating the arguments. You should remove the localPlayer and only call the function for your player. I would also not recommend using the varieble name "source". Better use the player, so it will be clearer to everyone: --wrong function Seed(source) if isElementWithinMarker(source, Pickup_Seed) then if getElementData(source, "GameLight:Seed") == false then setElementFrozen(source, true) setPedAnimation(source, "bar", "barcustom_get", 5000, true, false, false, false) triggerClientEvent(source, "EnableTimer3D_1", getRootElement()) setTimer(function() triggerClientEvent(localPlayer, source, "Remover_1", getRootElement()) end, 5000, 1) setTimer(function() setElementData(source, "GameLight:Seed", true) setElementFrozen(source, false) outputChatBox("#0000ff[Narkotikas] #ffffffTu savāci sēklu, ej iestādi to.", source, 255, 255, 255, true) setMarkerSize(Pickup_Planting, 1.5) setMarkerSize(Pickup_Seed, 0) end, 5000, 1) else outputChatBox("#0000ff[Narkotikas] #ffffffTev ir sēkla, iestādi to sākumā.", source, 255, 255, 255, true) end end end --right function Seed(player) if isElementWithinMarker(player, Pickup_Seed) then if getElementData(player, "GameLight:Seed") == false then setElementFrozen(player, true) setPedAnimation(player, "bar", "barcustom_get", 5000, true, false, false, false) triggerClientEvent(player, "EnableTimer3D_1", getRootElement()) setTimer(function() triggerClientEvent(player, "Remover_1", getRootElement()) end, 5000, 1) setTimer(function() setElementData(player, "GameLight:Seed", true) setElementFrozen(player, false) outputChatBox("#0000ff[Narkotikas] #ffffffTu savāci sēklu, ej iestādi to.", player, 255, 255, 255, true) setMarkerSize(Pickup_Planting, 1.5) setMarkerSize(Pickup_Seed, 0) end, 5000, 1) else outputChatBox("#0000ff[Narkotikas] #ffffffTev ir sēkla, iestādi to sākumā.", player, 255, 255, 255, true) end end end The same is true for the "onResourceStart" and "onClientResourceStart" events. These events occur when any resource is started, not just the one in which the event is written. An argument of type "resource" is passed to the function. Use validation to understand that this is exactly your resource: --wrong function StartBindKeySeed() for i, v in ipairs(getElementsByType("player")) do bindKey ( v, "h", "down", Seed ) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), StartBindKeySeed) --right function StartBindKeySeed(res) if not (resource == res) then return end for i, v in ipairs(getElementsByType("player")) do bindKey ( v, "h", "down", Seed ) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), StartBindKeySeed) I would also advise resetting the data element when the resource is turned off. This may cause problems. For example, when you restart, you will no longer be able to start work, and so on. Use this: OnResourceStop SetElementData Sorry, I can't check if the element is removed correctly, but judging by the code, there shouldn't be any problems. Correct your mistakes and check if everything works the way you want. Addition: And yet, in your functions there is no protection against repeated keystrokes. I can endlessly start planting drugs. You can see for yourself. Add a check to prevent this from happening. You can use the same SetElementData, or whatever is more convenient for you. Edited March 8, 2023 by Molvine addition Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now