Jump to content

getRootElement()


.:HyPeX:.

Recommended Posts

i only want to add it to a local player.

this way probably?

  
addCommandHandler("win",  
function () 
    if Dx_Rec then return end 
    Dx_Rec = {} 
    Dx_Rec.startTime = getTickCount() 
    Dx_Rec.endTime = Dx_Rec.startTime + 2000 
    Dx_Rec.easingFunction = "InQuad"  
    addEventHandler("onClientRender",localplayer, drawStuff) 
end) 

Link to comment
addCommandHandler("win", 
function (commandName, thePlayer) 
if thePlayer == getLocalPlayer() then 
    if Dx_Rec then return end 
    Dx_Rec = {} 
    Dx_Rec.startTime = getTickCount() 
    Dx_Rec.endTime = Dx_Rec.startTime + 2000 
    Dx_Rec.easingFunction = "InQuad" 
    addEventHandler("onClientRender",getRootElement(), drawStuff) 
end 
end) 

Link to comment
`addCommandHandler` on the client side doesn't have a player variable, since it's client side, is your meta.xml correct, if you don't know, post it(and tell us the file name of the script), because it should draw for the player only.

The meta is obiously right aswell as the script. The fact is that if i do it root, when a player does /win everyone sees it.

Link to comment
That's not possible, something else must be doing it.

it shouldnt but when a player does /win it shows it to everyone

Whole script :

  
local x,y = guiGetScreenSize() 
local announce = "default" 
local Streak = "1" 
announce = "default" 
Streak = "1" 
  
function setStreak(streak) 
Streak = streak 
end 
addEvent("setStreak", true) 
addEventHandler("setStreak", getRootElement(), setStreak) 
  
function setAnnounce(text) 
announce = text 
end 
addEvent("setAnnounce", true) 
addEventHandler("setAnnounce", getRootElement(), setAnnounce) 
  
function announce() 
executeCommandHandler ( "win", localplayer) 
end 
addEvent("announce", true) 
addEventHandler("announce", getRootElement(), announce) 
  
local Dx_Rec = nil 
addCommandHandler("win",  
function () 
    if Dx_Rec then return end 
    Dx_Rec = {} 
    Dx_Rec.startTime = getTickCount() 
    Dx_Rec.endTime = Dx_Rec.startTime + 2000 
    Dx_Rec.easingFunction = "InQuad"  
    addEventHandler("onClientRender", root, drawStuff) 
end) 
  
function drawStuff() 
local x,y = guiGetScreenSize() 
local now = getTickCount() 
local elapsedTime = now - Dx_Rec.startTime 
local duration = Dx_Rec.endTime - Dx_Rec.startTime 
local progress = elapsedTime / duration 
local fAnimationTime = getEasingValue(progress, Dx_Rec.easingFunction) 
local alpha = fAnimationTime*200 
local alphal = alpha/1.2 
    dxDrawRectangle ( 0, y/1.4, x, y, tocolor ( 0, 0, 0, alpha ) ) 
    dxDrawText ( "Winner: #ffffff " .. announce, 0, y/1.3, x, y, tocolor ( 0, 170, 255, alpha ), 1.3, "bankgothic", "center","top",nil,nil,nil, true, true ) 
    dxDrawText ( "Streak: #00aaff( #ffffffx" .. Streak .." #00aaff)", 0, y/1.15, x, y, tocolor ( 0, 170, 255, alpha ), 1.3, "bankgothic", "center","top",nil,nil,nil, true, true ) 
    dxDrawLine ( 0, y/1.02, x, y/1.02, tocolor ( 0, 170, 255, alphal ), 15 ) 
    dxDrawLine ( 0, y/1.4, x, y/1.4, tocolor ( 0, 170, 255, alphal ), 15 ) 
        if now > Dx_Rec.endTime then 
        removeEventHandler("onClientRender", getRootElement(), drawStuff) 
        addEventHandler("onClientRender", getRootElement(), Paused) 
        Pause = setTimer(function() 
                        removeEventHandler("onClientRender", root, Paused) 
                        Dx_Rec.startTime = getTickCount() 
                        Dx_Rec.endTime = Dx_Rec.startTime + 4000 
                        Dx_Rec.easingFunction = "OutQuad" --Fast at first then decelerating 
                        addEventHandler("onClientRender", root, UndrawStuff) 
                        end, 5000, 1) 
    end 
end 
  
function Paused() 
dxDrawRectangle ( 0, y/1.4, x, y, tocolor ( 0, 0, 0, 200 ) ) 
dxDrawText ( "Winner: #ffffff " .. announce, 0, y/1.3, x, y, tocolor ( 0, 170, 200, alpha ), 1.3, "bankgothic", "center","top",nil,nil,nil, true, true ) 
dxDrawText ( "Streak: #00aaff(#ffffff x" .. Streak .." #00aaff)", 0, y/1.15, x, y, tocolor ( 0, 170, 255, 200 ), 1.3, "bankgothic", "center","top",nil,nil,nil, true, true ) 
dxDrawLine ( 0, y/1.02, x, y/1.02, tocolor ( 0, 170, 255, 166 ), 15 ) 
dxDrawLine ( 0, y/1.4, x, y/1.4, tocolor ( 0, 170, 255, 166 ), 15 ) 
end 
  
function UndrawStuff() 
local x,y = guiGetScreenSize() 
local now = getTickCount() 
local elapsedTime = now - Dx_Rec.startTime 
local duration = Dx_Rec.endTime - Dx_Rec.startTime 
local progress = elapsedTime / duration 
local fAnimationTime = getEasingValue(progress, Dx_Rec.easingFunction) 
local alpha = (1-fAnimationTime)*200 
local alphal = alpha/1.2 
    dxDrawRectangle ( 0, y/1.4, x, y, tocolor ( 0, 0, 0, alpha ) ) 
    dxDrawText ( "Winner: #ffffff " .. announce, 0, y/1.3, x, y, tocolor ( 0, 170, 255, alpha ), 1.3, "bankgothic", "center","top",nil,nil,nil, true, true ) 
    dxDrawText ( "Streak: #00aaff(#ffffff x" .. Streak .." #00aaff)", 0, y/1.15, x, y, tocolor ( 0, 170, 255, alpha ), 1.3, "bankgothic", "center","top",nil,nil,nil, true, true ) 
    dxDrawLine ( 0, y/1.02, x, y/1.02, tocolor ( 0, 170, 255, alphal ), 15 ) 
    dxDrawLine ( 0, y/1.4, x, y/1.4, tocolor ( 0, 170, 255, alphal ), 15 ) 
if now > Dx_Rec.endTime - 200 then 
removeEventHandler("onClientRender", root, UndrawStuff) 
Dx_Rec = nil 
end     
end 
fileDelete("A_C.lua") 

This is on server side to let a userpanel output a winner: (server side)

  
            outputChatBox ("#00ff00* #FFFFFF" .. getPlayerName(winner) .." #FFFFFFhas won! He/She gets $#00ff00" .. tostring(cashToWin) .." #ffffffand #00ff00"..points.."#ffffff points || x"..WinStreak.."#00ff00!",getRootElement(),255,255,255,true) 
triggerClientEvent("Streaktext", root, WinStreak) 
local text = getPlayerName(winner) 
local streak = WinStreak 
triggerClientEvent("setAnnounce", getRootElement(), text) 
 triggerClientEvent("setStreak", getRootElement(), streak) 
triggerClientEvent("announce", getRootElement()) 

Link to comment
  • Moderators

Maybe you should take a look at the syntax of triggerClientEvent:

  
YouGotMail = triggerClientEvent ( getRootElement(), name, element ) 

You are already sending it to all players, because you haven't filled in it's destination.

And this is the trash for somebody who seriously is addicted too lua specifications.

  
outputChatBox(type(getRootElement))-- returns > function 
outputChatBox(type(getRootElement2))-- returns > nil [b](typo)[/b] 
outputChatBox(type(root))-- returns > userdata 
  

root = getRootElement() 

Returns the root variable.

The differed between root and getRootElement() is, that the one is just the out put of the function and the other one is the function it self.

Functions are making the code slow, so I prefer root a both getRootElement(). (believe it or not, but it is very true)

The result will not be high lagg, but the frames will go less smooth as before.

  
old = getTickCount()  
for i=1,1000000 do root = getRootElement() end  
outputChatBox(getTickCount()-old) 

99 ms

old = getTickCount()  
for i=1,1000000 do root = root end  
outputChatBox(getTickCount()-old) 

30 ms

Link to comment
Maybe you should take a look at the syntax of triggerClientEvent:
  
YouGotMail = triggerClientEvent ( getRootElement(), name, element ) 

You are already sending it to all players, because you haven't filled in it's destination.

And this is the trash for somebody who seriously is addicted too lua specifications.

  
outputChatBox(type(getRootElement))-- returns > function 
outputChatBox(type(getRootElement2))-- returns > nil [b](typo)[/b] 
outputChatBox(type(root))-- returns > userdata 
  

root = getRootElement() 

Returns the root variable.

The differed between root and getRootElement() is, that the one is just the out put of the function and the other one is the function it self.

Functions are making the code slow, so I prefer root a both getRootElement(). (believe it or not, but it is very true)

The result will not be high lagg, but the frames will go less smooth as before.

  
old = getTickCount()  
for i=1,1000000 do root = getRootElement() end  
outputChatBox(getTickCount()-old) 

99 ms

old = getTickCount()  
for i=1,1000000 do root = root end  
outputChatBox(getTickCount()-old) 

30 ms

all this is mostly senseless, did you read the topic? this is sent to all players when one of them does /win, not when i activate the trigger

Link to comment

all this is mostly senseless, did you read the topic? this is sent to all players when one of them does /win, not when i activate the trigger

What he said was quite interesting and useful. I'm certainly thankful he posted that here. You've already received quite a lot of useful advice from this thread too, If you are more appreciative perhaps people will be more willing to help.

Link to comment

all this is mostly senseless, did you read the topic? this is sent to all players when one of them does /win, not when i activate the trigger

What he said was quite interesting and useful. I'm certainly thankful he posted that here. You've already received quite a lot of useful advice from this thread too, If you are more appreciative perhaps people will be more willing to help.

I'm tired of reading without finding a fix to this

Link to comment
if your topic wasn't called getRootElement() and if I can find your question out of this....

Then I can answer your questions.....

Pls ask the question you have right now.

i only want to add it to a local player.

this way probably?

  
addCommandHandler("win",  
function () 
    if Dx_Rec then return end 
    Dx_Rec = {} 
    Dx_Rec.startTime = getTickCount() 
    Dx_Rec.endTime = Dx_Rec.startTime + 2000 
    Dx_Rec.easingFunction = "InQuad"  
    addEventHandler("onClientRender",localplayer, drawStuff) 
end) 

Just use getRootElement() and it will work fine

Did it, when a player does /win, all players get the event handler, can you answer my question IF you know abbout it instead of saying :~? :roll:

thanks

HyPeX

Link to comment

I tested the code on my local server, with 2 computers, and it is working properly for me, when I was typing /win, it was showing only on my screen. There might be a bug in the other files, or something else is causing it, search your other files for the trigger. Also, you should contact the maker of the userpanel if you don't know what is causing it, since we don't know all the code.

Link to comment
  • Moderators

@.:HyPeX:.

You sure there is no addCommandHandler with /win at serverside?

Because that would explain a lot.

A client addCommandHandler can't trigger something on serverside unless another function is sending it through. (which isn't there )

Link to comment

this is total server side..

i'll check it myself since this was based on multiple user reports.

i used before also a previous version of the script wich used to show it to everyone connected.. this is why i didnt doubted it. (it only had client side, no server script at all)

  
  
function command(player, cmd, ...) 
text = table.concat({...}," ") 
 local accName = getAccountName ( getPlayerAccount ( player ) )  
 if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) or isObjectInACLGroup ("user."..accName, aclGetGroup ( "SuperModerator" ) ) then 
 triggerClientEvent("announce2", getRootElement()) 
end 
end 
  
addCommandHandler("a", command, false, false) 
  
function setAnnounce(player, cmd, ...) 
text = table.concat({...}," ") 
 local accName = getAccountName ( getPlayerAccount ( player ) )  
 if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) or isObjectInACLGroup ("user."..accName, aclGetGroup ( "SuperModerator" ) ) then 
 triggerClientEvent("setAnnounce2", getRootElement(), text) 
end 
end 
  
addCommandHandler("sa", setAnnounce, false, false) 

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