Jump to content

triggering events problem


Piorun

Recommended Posts

I've got codes :

Client-side

  
addEventHandler("onClientClick", getRootElement(),  
function (button, state, ax, ay, wx, wy, wz) 
   if state=="up" then 
      triggerServerEvent("onPickupBiznesCreate",getLocalPlayer()) 
      outputChatBox(wx.." "..wy.." "..wz) 
   end 
end) 
  

Server-side

  
function pickupBiznes() 
   createPickup(wx,wy,wz,3,1273) 
end 
addEvent("onPickupBiznesCreate", true) 
addEventHandler("onPickupBiznesCreate", getRootElement(), pickupBiznes) 
  

Now i write what works:

Works only getting a cursor world pos x,y,z and outputing it to Chat Box, but i want create a pickup too on server side with this coords. Please help.

Link to comment

Then you should send those co-ordinates to the server to use them there, that's simple:

--client 
triggerServerEvent("onPickupBiznesCreate", getLocalPlayer(), wx, wy, wz) 

--server 
function pickupBiznes(wx, wy, wz) 
  createPickup(wx,wy,wz,3,1273) 
end 

Link to comment

Ok works everything, but now i add new code, and .. it doesn't work:

  
function biznesPickup(button, state, ax, ay, wx, wy, wz) 
   if state=="up" and button=="left" then 
      triggerServerEvent("onPickupBiznesCreate",getLocalPlayer(), wx, wy, wz) 
      outputChatBox(wx.." "..wy.." "..wz) 
   end 
end 
  
addEvent("onPickup3Dtext", true) 
addEventHandler("onPickup3Dtext", getRootElement(), biznesPickup) 
addEventHandler("onClientClick", getRootElement(), biznesPickup) 
  
function endBiznesCreation(wx, wy, wz) 
triggerEvent("onPickup3Dtext", getLocalPlayer(), wx, wy, wz) 
  local px, py, pz = getElementPosition (getLocalPlayer()) 
    dist = getDistanceBetweenPoints3D ( px, py, pz, wx, wy, wz ) 
    if dist < 20.0 then 
       local x, y = getScreenFromWorldPosition ( wx, wy, wz, true ) 
       if x then 
          dxDrawText("Biznes",x,y+2,x+2,y,tocolor(0,0,0),1,"default-bold","center","center") 
          dxDrawText("Biznes",x,y,x,y,tocolor(49,140,231),1,"default-bold","center","center") 
       end 
    end 
end 
addEventHandler("onClientRender",getRootElement(),endBiznesCreation) 
  

Link to comment
  • Moderators
addEventHandler("onPickup3Dtext", getRootElement(), biznesPickup) 
-- and 
triggerEvent("onPickup3Dtext", getLocalPlayer(), wx, wy, wz) 

What are you trying to do ? It can't works because wx, wy, wz are not defined in the endBiznesCreation function

If you want to use variables in others functions, you have to transform those variables in globals variables !

I think that I understood what do you want to do:

  
function biznesPickup(button, state, ax, ay, wx, wy, wz) 
   if state=="up" and button=="left" then 
      triggerServerEvent("onPickupBiznesCreate",getLocalPlayer(), wx, wy, wz) 
      outputChatBox(wx.." "..wy.." "..wz) 
    -- transform wx, wy, wz to globals variables 
      wx = wx 
      wy = wy 
      wz = wy 
   end 
end 
  
addEvent("onPickup3Dtext", true) 
-- addEventHandler("onPickup3Dtext", getRootElement(), biznesPickup) 
addEventHandler("onClientClick", getRootElement(), biznesPickup) 
  
function endBiznesCreation() 
    -- triggerEvent("onPickup3Dtext", getLocalPlayer(), wx, wy, wz) 
    local px, py, pz = getElementPosition (getLocalPlayer()) 
    dist = getDistanceBetweenPoints3D ( px, py, pz, wx, wy, wz ) 
    if dist < 20.0 then 
       local x, y = getScreenFromWorldPosition ( wx, wy, wz, true ) 
       if x then 
          dxDrawText("Biznes",x,y+2,x+2,y,tocolor(0,0,0),1,"default-bold","center","center") 
          dxDrawText("Biznes",x,y,x,y,tocolor(49,140,231),1,"default-bold","center","center") 
       end 
    end 
end 
addEventHandler("onClientRender",getRootElement(),endBiznesCreation) 
  

Link to comment
  • Moderators

See the getScreenFromWorldPosition syntax:

float float getScreenFromWorldPosition ( float x, float y, float z, [ float edgeTolerance=0, bool relative=true ] )

So take this line:

local x, y = getScreenFromWorldPosition ( wx, wy, wz )-- it's already in relativ 

:!:This code works only with the latest created pickup :!:

If you want more than 1 pickup, you have to make a table and insert the wx, wy, wz in this table at each click

Link to comment

Now i've got this code:

  
addEventHandler("onClientClick", getRootElement(), 
function (button, state, ax, ay, wx, wy, wz) 
   if state=="up" and button=="left"then 
      triggerServerEvent("onPickupBiznesCreate",getLocalPlayer(), wx, wy, wz) 
      wx = wx 
      wy = wy 
      wz = wz 
   end 
end) 
  
function endBiznesCreation() 
    --triggerEvent("onPickup3Dtext", getLocalPlayer(), wx, wy, wz) 
    local px, py, pz = getElementPosition (getLocalPlayer()) 
    dist = getDistanceBetweenPoints3D ( px, py, pz, wx, wy, wz ) 
    if dist < 20.0 then 
       local x, y = getScreenFromWorldPosition ( wx, wy, wz ) 
       if x then 
          dxDrawText("Biznes",x,y+2,x+2,y,tocolor(0,0,0),1,"default-bold","center","center") 
          dxDrawText("Biznes",x,y,x,y,tocolor(49,140,231),1,"default-bold","center","center") 
       end 
    end 
end 
addEventHandler("onClientRender",getRootElement(),endBiznesCreation) 
  

dxText doesn't work still ... and - how to create a table with wx, wy, wz???

Link to comment

Why do you need such thing? you could easily use element data and then loop with every pickup.

--client side

  
addEventHandler("onClientClick", getRootElement(), 
function (button, state, ax, ay, wx, wy, wz) 
   if state=="up" and button=="left"then 
      triggerServerEvent("onPickupBiznesCreate",getLocalPlayer(), wx, wy, wz) 
   end 
end) 
  
function endBiznesCreation() 
    for i,v in pairs(getElementsByType("pickup")) do 
    if getElementData(v,"text") then 
    local px, py, pz = getElementPosition (getLocalPlayer()) 
    local wx, wy, wz = getElementPosition(v) 
    dist = getDistanceBetweenPoints3D ( px, py, pz, wx, wy, wz ) 
    if dist < 20.0 then 
       local x, y = getScreenFromWorldPosition ( wx, wy, wz ) 
       if x then 
          dxDrawText("Biznes",x,y+2,x+2,y,tocolor(0,0,0),1,"default-bold","center","center") 
          dxDrawText("Biznes",x,y,x,y,tocolor(49,140,231),1,"default-bold","center","center") 
             end 
          end 
       end 
    end 
end 
addEventHandler("onClientRender",getRootElement(),endBiznesCreation) 

--server side

function pickupBiznes(wx, wy, wz) 
  pickup = createPickup(wx,wy,wz,3,1273) 
  setElementData(pickup,"text",true) 
end 
addEvent("onPickupBiznesCreate", true) 
addEventHandler("onPickupBiznesCreate", getRootElement(), pickupBiznes) 

Should work (not tested)

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