Jump to content

race state


Recommended Posts

local x,y = guiGetScreenSize() 
local defScale = 1 
local currentScale = defScale 
local maxScale = 2 
local step = 0.05 -- How fast to change the size 
local turn = true -- true = increase size, false = decrease size 
local text = "Loading next map" 
local font = dxCreateFont("myFont.ttf",10) 
  
function renderPulse() 
  if turn == true then -- If we increase the value 
    currentScale = currentScale + step 
    if currentScale > maxScale then 
      currentScale = maxScale 
      turn = false -- Reached max? Then make it go back 
    end 
  else 
    currentScale = currentScale - step 
    if currentScale < defScale then 
      currentScale = defScale 
      turn = true 
    end 
  end 
  local width = dxGetTextWidth(text,currentScale,font) 
  local height = dxGetFontHeight(currentScale,font) 
  dxDrawText(text,x/2-width/2,y/2-height/2,width,height,tocolor(255,255,255,255),currentScale,font) 
end 
addEventHandler("onClientRender",getRootElement(),renderPulse) 

I need to make this work only if race state is "LoadingMap"

Link to comment
function exampleFunction_Handler(newState, oldState) 
    if(newState == "LoadingMap") then 
        -- Your code here 
    end 
end 
addEvent("onRaceStateChanging", false) 
addEventHandler("onRaceStateChanging", getRootElement(), exampleFunction_Handler) 

This event is server-side.

Link to comment

You'll need to change the boolean from false to true if you want to be able to remotely trigger it from a client.

Nvm, misunderstood what you're trying to do.

Just create an event for your client-side function, and trigger it via the server-side event I provided.

Link to comment

A little help mby ? :D

function exampleFunction_Handler(newState, oldState) 
    if(newState == "LoadingMap") then 
         triggerClientEvent ( dont know what to write here.) 
    end 
end 
addEvent("onRaceStateChanging", false) 
addEventHandler("onRaceStateChanging", getRootElement(), exampleFunction_Handler) 

Link to comment

Create the event client-side using addEvent, then use an event handler. IE;

function myClientFunction_Handler() 
    -- Wow, such code. Very program 
end 
addEvent("myEvent", true) -- True means you can trigger this event via the server. False means you can not. 
addEventHandler("myEvent", getRootElement(), myClientFunction_Handler) -- You'll of course need an event handler. 

Then trigger it via the server like this;

triggerClientEvent("myEvent", getRootElement()) -- This will trigger for all players. 
triggerClientEvent(playerElement, "myEvent", getRootElement()) -- This will trigger for the specified player element only. 

Edit: Of course you can use it to transfer data as well. Example;

function myServerFunction_Handler() 
    local argumentOne = "Hello World!"; 
    local argumentTwo = 1.337; 
    triggerClientEvent("myEvent", getRootElement(), argumentOne, argumentTwo) 
end 
  
function myClientFunction_Handler(arg1, arg2) -- You can define those with whatever name you want 
    outputChatBox(arg1) 
    outputChatBox(tostring(arg2)) -- Since 2nd variable is a float value - convert it to a string 
end 
addEvent("myEvent", true) 
addEventHandler("myEvent", getRootElement(), myClientFunction_Handler) 

Link to comment

Did i fail ?

Client:

local x,y = guiGetScreenSize() 
local defScale = 1 
local currentScale = defScale 
local maxScale = 2 
local step = 0.05 -- How fast to change the size 
local turn = true -- true = increase size, false = decrease size 
local text = "Loading next map" 
local font = dxCreateFont("myFont.ttf",10) 
  
  
function myClientFunction_Handler() 
  if turn == true then -- If we increase the value 
    currentScale = currentScale + step 
    if currentScale > maxScale then 
      currentScale = maxScale 
      turn = false -- Reached max? Then make it go back 
    end 
  else 
    currentScale = currentScale - step 
    if currentScale < defScale then 
      currentScale = defScale 
      turn = true 
    end 
  end 
  local width = dxGetTextWidth(text,currentScale,font) 
  local height = dxGetFontHeight(currentScale,font) 
  dxDrawText(text,x/2-width/2,y/2-height/2,width,height,tocolor(255,255,255,255),currentScale,font) 
end 
addEvent("myEvent", true)  
addEventHandler("myEvent", getRootElement(), myClientFunction_Handler) 

Server:

function exampleFunction_Handler(newState, oldState) 
    if(newState == "LoadingMap") then 
        triggerClientEvent(playerElement, "myEvent", getRootElement()) 
    end 
end 
addEvent("onRaceStateChanging", false) 
addEventHandler("onRaceStateChanging", getRootElement(), exampleFunction_Handler) 

Link to comment
  
local x,y = guiGetScreenSize() 
local defScale = 1 
local currentScale = defScale 
local maxScale = 2 
local step = 0.05 -- How fast to change the size 
local turn = true -- true = increase size, false = decrease size 
local text = "Loading next map" 
local font = dxCreateFont("myFont.ttf",10) 
  
  
function myClientFunction_Handler() 
  if turn == true then -- If we increase the value 
    currentScale = currentScale + step 
    if currentScale > maxScale then 
      currentScale = maxScale 
      turn = false -- Reached max? Then make it go back 
    end 
  else 
    currentScale = currentScale - step 
    if currentScale < defScale then 
      currentScale = defScale 
      turn = true 
    end 
  end 
  local width = dxGetTextWidth(text,currentScale,font) 
  local height = dxGetFontHeight(currentScale,font) 
  dxDrawText(text,x/2-width/2,y/2-height/2,width,height,tocolor(255,255,255,255),currentScale,font) 
end 
  
function AddingEvent() 
    addEventHandler("onClientRender",root,myClientFunction_Handler) 
end 
addEvent("myEvent", true) 
addEventHandler("myEvent", getRootElement(), AddingEvent) 

Link to comment
Well you need to define the player element. As of now it's returning nil - and as such the event won't be triggered. Try removing the playerElement.

Then it will trigger for all players currently on the server.

Did you do that?

Link to comment
--server 
function exampleFunction_Handler(newState, oldState) 
    if(newState == "LoadingMap") then 
        triggerClientEvent(playerElement, "myEvent", getRootElement()) 
    elseif (newState == "Running") then  
        triggerClientEvent(playerElement,"removeEvent",getRootElement()) 
    end 
end 
addEvent("onRaceStateChanging", false) 
addEventHandler("onRaceStateChanging", getRootElement(), exampleFunction_Handler) 
  
 --client 
local x,y = guiGetScreenSize() 
local defScale = 1 
local currentScale = defScale 
local maxScale = 2 
local step = 0.05 -- How fast to change the size 
local turn = true -- true = increase size, false = decrease size 
local text = "Loading next map" 
local font = dxCreateFont("myFont.ttf",10) 
  
  
function myClientFunction_Handler() 
  if turn == true then -- If we increase the value 
    currentScale = currentScale + step 
    if currentScale > maxScale then 
      currentScale = maxScale 
      turn = false -- Reached max? Then make it go back 
    end 
  else 
    currentScale = currentScale - step 
    if currentScale < defScale then 
      currentScale = defScale 
      turn = true 
    end 
  end 
  local width = dxGetTextWidth(text,currentScale,font) 
  local height = dxGetFontHeight(currentScale,font) 
  dxDrawText(text,x/2-width/2,y/2-height/2,width,height,tocolor(255,255,255,255),currentScale,font) 
end 
  
function AddingEvent() 
    addEventHandler("onClientRender",root,myClientFunction_Handler) 
end 
addEvent("myEvent", true) 
addEventHandler("myEvent", getRootElement(), AddingEvent) 
  
function RemovingEvent() 
    removeEventHandler("onClientRender",root,myClientFunction_Handler) 
end 
addEvent("removeEvent", true) 
addEventHandler("removeEvent", getRootElement(), RemovingEvent) 

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