Jump to content

[Help] with triggerServerEvent


kamani

Recommended Posts

Hey all :) I have this script, but don't run perfectly..

Please help with this script.. whats wrong :) ? :roll::roll:

CLIENT:

  
function GoToJob(source) 
outputChatBox("Hey, have a job!", source) 
givePlayerMoney(source,-500) 
triggerServerEvent("StartJobCheckPoint",getLocalPlayer()) 
end 
  

SERVER:

  
function JobCP() 
local Job1 = createMarker( -1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder',0.8, 0, 255, 0, getRootElement()) 
end 
addEvent("StartJobCheckPoint", true) 
addEvent("StartJobCheckPoint", getRootElement(), JobCP() 
end) 
  

Don't show job1 checkpoint.

Link to comment

I change addEvent("StartJobCheckPoint", getRootElement(), JobCP() to addEvent("StartJobCheckPoint", getRootElement(), JobCP) and script is now :

  
function JobCP() 
local Job1 = createMarker( -1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder',0.8, 0, 255, 0, getRootElement()) 
end 
addEvent("StartJobCheckPoint", true) 
addEvent("StartJobCheckPoint", getRootElement(), JobCP) 
end) 
  

Link to comment

CLIENT:

  
function GoToJob(source) 
    outputChatBox("Hey, have a job!") 
    takePlayerMoney(500) 
    triggerServerEvent("StartJobCheckPoint",getLocalPlayer()) 
end 
  

SERVER:

  
function JobCP() 
    local Job1 = createMarker( -1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder',0.8, 0, 255, 0, getRootElement()) 
end 
addEvent("StartJobCheckPoint", true) 
addEvent[color=#FF0000]Handler[/color]("StartJobCheckPoint", getRootElement(), JobCP) 
  

Edited by Guest
Link to comment

Okey, thanks very much :)

now it this.. (SERVER)

function JobCP() 
local Job1 = createMarker( -1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder',0.8, 0, 255, 0, getRootElement()) 
end 
addEvent("StartJobCheckPoint", true) 
addEventHandler("StartJobCheckPoint", getRootElement(), JobCP) 
  
function OnJobCheckpoint(hitElement, matchingDimension) 
 if getElementType(hitElement) == "player" then 
 addEvent ("ShowGUI", true) 
 triggerClientEvent ( hitElement, "ShowGUI", getRootElement(), "Hello World!") 
 end 
end 
addEventHandler( "onMarkerHit", Job1, OnJobCheckpoint ) 

CLIENT:

function ShowGuiWindow() 
guiSetVisible (Window_PA, true) 
showCursor(true) 
end 
addEvent ("ShowGUI", true) 
addEventHandler( "ShowGUI", getRootElement(), ShowGuiWindow) 

when i go to the checkpoint "job1" , gui doesn't show!

Link to comment

your server script on start is:

1. defining a function

2. adding custom event

3. adding event handler

4. defining a function

5. adding onMarkerHit attached to nonexistent element.

Post whole code you have if you need more help. (i assume THERE IS more code, as your Job1 will never be created with this scripts, and you are saying it's not doing anything after hitting it - so i have to exist.

Link to comment

-- SERVER

local Job2 = createMarker( -1985.6575927734, 476.59652709961, 34.021896362305, 'cylinder', 1.5, 0, 255, 0, getRootElement()) 
  
function ShowJob2(hitElement, matchingDimension) 
  if getElementType(hitElement) == "player" then 
  addEvent ("JobSend2", true) 
  triggerClientEvent ( hitElement, "JobSend2", getRootElement(), "Hello World!") 
  end   
end 
addEventHandler( "onMarkerHit", Job2 ,ShowJob2 ) 
  
function InJob1() 
local Job1 = createMarker( -1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder',0.8, 0, 255, 0, getRootElement()) 
end 
addEvent("OfJob1", true) 
addEventHandler("OfJob1", getRootElement(), InJob1 ) 
  
function ShowJob1(hitElement, matchingDimension) 
  if getElementType(hitElement) == "player" then 
  addEvent ("JobSend1", true) 
  triggerClientEvent ( hitElement, "JobSend1", getRootElement(), "Hello world!") 
  end 
end 
addEventHandler( "onMarkerHit", Job1 ,ShowJob1) 

-- CLIENT

  
  
function GoToJob(source) 
if (getPlayerMoney(source)<=500) then 
    outputChatBox("You don't have a money!",source,255) 
else 
addEvent("OfJob1",true) 
guiSetVisible(JobsWindow,false) 
outputChatBox("You entered to job!", source) 
showCursor(false) 
triggerServerEvent("OfJob1",getLocalPlayer()) 
end 
end 
  
function ShowGui1()  
TurnOnWindows1() 
guiSetVisible (Window1, true) 
showCursor (true) 
end 
addEvent ("JobSend1", true) 
addEventHandler( "JobSend1", getRootElement(), ShowGui1 ) 
  
  
function ShowGui2()  
TurnOnWindows2() 
guiSetVisible (Window2, true) 
showCursor (true) 
end 
addEvent ("JobSend2", true) 
addEventHandler( "JobSend2", getRootElement(), ShowGui2 ) 

Job2 run perfect, but job1 don't show me GUI ;(

Link to comment

highly unlikely that your debug is empty

function InJob1() 
  local Job1 = createMarker( -1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder',0.8, 0, 255, 0, getRootElement()) 
end 

"local" variables declared inside of a function don't exist outside of the function. so this:

addEventHandler( "onMarkerHit", Job1 ,ShowJob1) 

should give you error. your Job2 marker is declared outside. you should do the same with Job1 marker variable.

Link to comment

mh, but when i changed script for this:

local Job2 = createMarker( -1985.6575927734, 476.59652709961, 34.021896362305, 'cylinder', 1.5, 0, 255, 0, getRootElement()) 
local Job1 = createMarker( -1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder',0.8, 0, 255, 0, getRootElement()) 
  
function ShowJob2(hitElement, matchingDimension) 
  if getElementType(hitElement) == "player" then 
  addEvent ("JobSend2", true) 
  triggerClientEvent ( hitElement, "JobSend2", getRootElement(), "Hello World!") 
  end   
end 
  
function ShowJob1(hitElement, matchingDimension) 
  if getElementType(hitElement) == "player" then 
  addEvent ("JobSend1", true) 
  triggerClientEvent ( hitElement, "JobSend1", getRootElement(), "Hello world!") 
  end 
end 
addEventHandler( "onMarkerHit", Job2 ,ShowJob2 ) 
addEventHandler( "onMarkerHit", Job1 ,ShowJob1) 

Marker Job2 run perfectly, but Marker Job1 don't show GUI for me, when i go on job1.. Maybe problem in GUI :?:

maybe is it possible to do otherwise disable or turn marker ?

EDIT: This script idea is this:

When i go to Marker (Job2) for me create Marker (Job1) and when i go to Marker (Job1) for me just show GUI window, But don't show any windows... omg, but when i go on Job 2 marker, Marker job1 created!

Link to comment
EDIT: This script idea is this:

When i go to Marker (Job2) for me create Marker (Job1) and when i go to Marker (Job1) for me just show GUI window, But don't show any windows... omg, but when i go on Job 2 marker, Marker job1 created!

i doubt that i understand the idea (your explanation differs from your scripts somewhat, it also defies basic logic, like first 2 then 1, wtf?). and you're posting only parts of the code. like where is GoToJob() function triggered?

anyway, here's what i come up with, fixing the stuff that you've posted:

server:

Job1 = false 
Job2 = createMarker(-1985.6575927734, 476.59652709961, 34.021896362305, 'cylinder', 1.5, 0, 255, 0, 128) 
  
function ShowJob2(hitElement, matchingDimension) 
  if getElementType(hitElement) == "player" then 
    triggerClientEvent(hitElement, "JobSend2", getRootElement()) 
  end   
end 
addEventHandler( "onMarkerHit", Job2, ShowJob2) 
  
function ShowJob1(hitElement, matchingDimension) 
  if getElementType(hitElement) == "player" then 
    triggerClientEvent(hitElement, "JobSend1", getRootElement()) 
  end 
end 
  
function InJob1() 
  Job1 = createMarker(-1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder', 0.8, 0, 255, 0, 128) 
  addEventHandler("onMarkerHit", Job1, ShowJob1) 
end 
addEvent("OfJob1", true) 
addEventHandler("OfJob1", getRootElement(), InJob1) 

client:

function GoToJob() 
  if (getPlayerMoney(getLocalPlayer())<=500) then 
    outputChatBox("You don't have a money!", 255, 0, 0) 
  else 
    guiSetVisible(JobsWindow,false) 
    outputChatBox("You entered to job!") 
    showCursor(false) 
    triggerServerEvent("OfJob1", getLocalPlayer()) 
  end 
end 
  
function ShowGui1()  
  TurnOnWindows1() 
  guiSetVisible(Window1, true) 
  showCursor(true) 
end 
addEvent("JobSend1", true) 
addEventHandler("JobSend1", getRootElement(), ShowGui1) 
  
  
function ShowGui2()  
  TurnOnWindows2() 
  guiSetVisible(Window2, true) 
  showCursor(true) 
end 
addEvent("JobSend2", true) 
addEventHandler("JobSend2", getRootElement(), ShowGui2) 

Link to comment

Okey, this is full script...

SERVER:

  
Job1 = false 
Job2 = createMarker( -1985.6575927734, 476.59652709961, 34.021896362305, 'cylinder', 1.5, 0, 255, 0, 128) 
function HitOnJob2(hitElement, matchingDimension) 
  if getElementType(hitElement) == "player" then 
  triggerClientEvent ( hitElement, "OpenJob2Gui", getRootElement()) 
  end   
end 
addEventHandler( "onMarkerHit",Job2 ,HitOnJob2 ) 
addEvent("CreateJob1CP", true) 
addEventHandler("CreateJob1CP", getRootElement(),  
function() 
Job1 = createMarker( -1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder',0.8, 0, 255, 0, 128) 
end) 
function HitOnJob1(hitElement, matchingDimension) 
  if getElementType(hitElement) == "player" then 
  triggerClientEvent ( hitElement, "OpenJob1Gui", getRootElement()) 
  end 
end 
addEventHandler( "onMarkerHit", Job1 ,HitOnJob1 ) 
  

CLIENT:

  
function Job2Gui() 
j2window = guiCreateWindow(386,330,519,363,"JOB SYSTEM",false) 
Tabfield = guiCreateTabPanel(37,58,442,213,false,j2window) 
field1 = guiCreateTab("Informacija",Tabfield) 
TabText1 = guiCreateLabel(0,3,442,179,"INFORMATION",false,field1) 
guiLabelSetColor(TabText1,255,255,255) 
guiLabelSetVerticalAlign(TabText1,"top") 
guiLabelSetHorizontalAlign(TabText1,"left",false) 
field2 = guiCreateTab("Workers",Tabfield) 
TabText2 = guiCreateLabel(1,4,440,175,"TEXT ABOUT WORKERS",false,field2) 
guiLabelSetColor(TabText2,255,255,255) 
guiLabelSetVerticalAlign(TabText2,"top") 
guiLabelSetHorizontalAlign(TabText2,"left",false) 
field3 = guiCreateTab("WARNING",Tabfield) 
TabText3 = guiCreateLabel(0,7,442,175,"INFORMATION",false,field3) 
guiLabelSetColor(TabText3,255,255,255) 
guiLabelSetVerticalAlign(TabText3,"top") 
guiLabelSetHorizontalAlign(TabText3,"left",false) 
Text = guiCreateLabel(39,274,310,33,"u want work? click work!",false,j2window) 
guiLabelSetColor(Text ,255,255,255) 
guiLabelSetVerticalAlign(Text ,"top") 
guiLabelSetHorizontalAlign(Text ,"left",false) 
WorkButton = guiCreateButton(44,318,121,29,"Work",false,j2window) 
CloseButton = guiCreateButton(196,319,121,27,"Close",false,j2window) 
addEventHandler("onClientGUIClick",CloseButton,close,false) 
addEventHandler("onClientGUIClick",WorkButton,work,false) 
end 
  
function work(source) 
if (getPlayerMoney(source)<=300) then 
outputChatBox("u don't have 300$",source,255) 
else 
guiSetVisible(j2window,false) 
outputChatBox("okey man,go to checkpoint to start work!", source) 
showCursor(false) 
triggerServerEvent("CreateJob1CP",source) 
end 
end 
  
addEvent ("OpenJob2Gui", true) 
addEventHandler( "OpenJob2Gui", getRootElement(), 
function()   
j2window() 
guiSetVisible(j2window, true) 
showCursor(true) 
end) 
  
addEvent ("OpenJob1Gui", true) 
addEventHandler( "OpenJob1Gui", getRootElement(), 
function()    
j2window() 
guiSetVisible(j2window, true) 
showCursor(true) 
end) 
  

i want create, when i go in job1 marker, show for me job2gui GUI.

when i been in job2 marker, gui show and when i click work button marker job1 created, but i when i go in job1 marker, job2gui GUI don't show for me.

Link to comment

why you always changing the names of the functions and everything, it is hard to understand as it is already.

1. j2window = guiCreateWindow(386,330,519,363,"JOB SYSTEM",false)

later you have a function (?) with this name. wtf?

2. function work(source)

"source" is a hidden variable passed from event, you dont need to (and better not to) assign anything to it.

in this case source is GUI element (not player!), and first argument is button (not player!).

use function work() and replace the rest "source"s in the function with getLocalPlayer() (clientside outputChatBox() does not even need it).

3. addEventHandler( "onMarkerHit", Job1, HitOnJob1)

i didn't just placed this event handler after createMarker for no reason. now you have it again in the end of the script, while the marker is created in a function (which is NOT called before the handler = no marker element to attach to), so you need to attach the handler to a marker ELEMENT when it exists:

addEventHandler("CreateJob1CP", getRootElement(), 
  function() 
  Job1 = createMarker( -1979.3596191406, 483.17581176758, 34.100391387939, 'cylinder',0.8, 0, 255, 0, 128) 
  addEventHandler("onMarkerHit", Job1, HitOnJob1) 
end) 

PS: are you sure your /debugscript 3 is empty? are you even using it?

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