Piorun Posted March 26, 2011 Posted March 26, 2011 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.
DakiLLa Posted March 26, 2011 Posted March 26, 2011 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
Piorun Posted March 26, 2011 Author Posted March 26, 2011 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)
Moderators Citizen Posted March 26, 2011 Moderators Posted March 26, 2011 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)
Piorun Posted March 26, 2011 Author Posted March 26, 2011 I want to create a pickup (this is not a porblem, because it's working cool) with 3D text (and that's the problem), but i don't know how to move coords from one function to any other function. @up your code doesn't work.
Moderators Citizen Posted March 26, 2011 Moderators Posted March 26, 2011 @up your code doesn't work. Have you try to click on the world ?
Piorun Posted March 26, 2011 Author Posted March 26, 2011 Yup. Still function is creating a pickup, but without a dxText.
Moderators Citizen Posted March 26, 2011 Moderators Posted March 26, 2011 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
Piorun Posted March 26, 2011 Author Posted March 26, 2011 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???
Castillo Posted March 27, 2011 Posted March 27, 2011 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)
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