Jump to content

Serverside text


Recommended Posts

Hello, How i can use the following to display a "math.random" numbers and make it disappear after 6 seconds? Like example if i killed somebody a text with a random number will appear and after 6 seconds exactly it will disappear, thanks.

textDisplayAddObserver 
textDisplayAddText 
textDestroyDisplay 
textDestroyTextItem 

Server (not tested):

function text(player) 
   local test = math.random(100, 200) 
   local serverDisplay = textCreateDisplay() 
   textDisplayAddObserver ( serverDisplay, player ) 
   local serverText = textCreateTextItem ( tonumber(test), 0.5, 0.5 ) 
   textDisplayAddText ( serverDisplay, serverText ) 
addEventHandler("onPlayerWasted", root, text) 
  
  
   setTimer ( text, 6000, 1, 
   textDestroyDisplay ( serverDisplay ) 
   textDestroyTextItem( serverText ) 
)   
end 

Link to comment

remove player at line 1, and replace player inside the function with source. and put the timer inside the function and make another function inside it with textDestroyDisplay and textDestroyItem. so it will be like:

  
function text () 
local test = math.random(100, 200) 
   local serverDisplay = textCreateDisplay() 
   textDisplayAddObserver ( serverDisplay, source) 
   local serverText = textCreateTextItem ( tonumber(test), 0.5, 0.5 ) 
   textDisplayAddText ( serverDisplay, serverText ) 
   setTimer(function () 
 textDestroyDisplay ( serverDisplay ) 
   textDestroyTextItem( serverText ) 
end,6000,1) 
end 
addEventHandler("onPlayerWasted",root,text) 
  

Link to comment
  
function text () 
local test = math.random(100, 200) 
   local serverDisplay = textCreateDisplay() 
for _,v in pairs (getElementsByType("player") ) do -- loop through all players 
   textDisplayAddObserver ( serverDisplay, v) 
end -- loop ends 
   local serverText = textCreateTextItem ( tonumber(test), 0.5, 0.5 ) 
  
   textDisplayAddText ( serverDisplay, serverText ) 
  
   setTimer(function () 
  
 textDestroyDisplay ( serverDisplay ) 
  
   textDestroyTextItem( serverText ) 
  
end,6000,1) 
  
end 
  
addEventHandler("onPlayerWasted",root,text) 

btw source is the player who died so it will create text only for the player and the code I posted below will display text for all players.

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