Jump to content

How to send text from server side?


3HAXAPb94

Recommended Posts

Posted

You can read this post for an example - it's from client to server. But should work the other way.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

--client

addEvent ("onUpgradeText",true) 
addEventHandler ("onUpgradeText",root,weaponBar) 
 function weaponBar(message) 
 if not message then  
 message = "no upgrade" 
dxDrawRectangle (posX*2+300,posY,250,100, tocolor (0,0,0,150)) 
dxDrawRectangle (posX*2+300,posY,250,Hvis, tocolor (255,255,255,150)) 
dxDrawText ("Upgrade",posX*2+300,-(vis)+50-(Hvis),sX,sY,tocolor (255,255,255,255),1.5,"default-bold", "center", "center") 
dxDrawText (message,posX*2+300,-(vis)+100-(Hvis),sX,sY,tocolor (255,255,255,255),2,"default-bold", "center", "center") 
 end 
    end 
 addEventHandler ("onClientRender",root, weaponBar) 
  

--server

  
function someFucntion () 
message = "Barrel" 
triggerClientEvent ("onUpgradeText",source,message) 
end 

its doesnt work...

Posted
function someFucntion () 
message = "Barrel" 
triggerClientEvent ("onUpgradeText",source,message) 
end 

You don't have any event handler attached to this function, so as far as I can see - source would be nil. Also I believe you would have to construct your triggerClientEvent like this;

triggerClientEvent (source, "onUpgradeText", message) 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

Ah, I mis-read the wiki. Try this;

triggerClientEvent (source, "onUpgradeText", getRootElement(), message) 

Source being the element you want to send the message to. Make sure there actually is a source for the function you're working with. Also if there are errors and/or warnings - post them.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

Surely you havent done what he says, how are you triggering the function? (server)

My ingame nick is ~HyPeX~

BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager

gKhdyRJ.png

Posted (edited)
local luck = math.random(1,5) 
if luck == 1 then 
message = "Barrel" 
triggerClientEvent (source, "onUpgradeText", getRootElement(), message) 
giveMeBarrel () 
elseif luck == 2 then 
message = "Aura" 
triggerClientEvent (source, "onUpgradeText", getRootElement(), message) 
giveMeAura() 
elseif luck ==3 then 
message = "Fix" 
triggerClientEvent (source, "onUpgradeText", getRootElement(), message) 
fixVehicle ()  
elseif luck == 4 then 
message = "Nitro" 
triggerClientEvent (source, "onUpgradeText", getRootElement(), message) 
nitro () 
elseif luck == 5 then 
message = "Rocket" 
triggerClientEvent (source, "onUpgradeText", getRootElement(), message) 
doShoot() 
end 

Its server side

PS i use this if player get racepickup

Edited by Guest
Posted
addEvent ("onUpgradeText",true) 
addEventHandler ("onUpgradeText",root,weaponBar) 
 function weaponBar(message) 
 if not message then 
 message = "not upgrade" 
dxDrawRectangle (posX*2+300,posY,250,100, tocolor (0,0,0,150)) 
dxDrawRectangle (posX*2+300,posY,250,Hvis, tocolor (255,255,255,150)) 
dxDrawText ("Upgrade",posX*2+300,-(vis)+50-(Hvis),sX,sY,tocolor (255,255,255,255),1.5,"default-bold", "center", "center") 
dxDrawText (message,posX*2+300,-(vis)+100-(Hvis),sX,sY,tocolor (255,255,255,255),2,"default-bold", "center", "center") 
 end 
 end 
 addEventHandler ("onClientRender",root, weaponBar) 

client side

Posted

What event handler are you using for the server-side code you pasted? Are you sure source is returned as a player element?

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted
This should work.
triggerClientEvent ( "onUpgradeText", source, message ) 

bool triggerClientEvent ( [element sendTo=getRootElement()], string name, element theElement, [arguments...] ) 

First argument is the element to send it to.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted
triggerClientEvent ( source, "onUpgradeText", source, message ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

That'll trigger to everyone, not just to 'source'.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Post both client and server side scripts.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
--Client 
addEvent ("onUpgradeText",true) 
addEventHandler ("onUpgradeText",root,weaponBar) 
 function weaponBar(message) 
 if not message then 
 message = "not upgrade" 
dxDrawRectangle (posX*2+300,posY,250,100, tocolor (0,0,0,150)) 
dxDrawRectangle (posX*2+300,posY,250,Hvis, tocolor (255,255,255,150)) 
dxDrawText ("Upgrade",posX*2+300,-(vis)+50-(Hvis),sX,sY,tocolor (255,255,255,255),1.5,"default-bold", "center", "center") 
dxDrawText (message,posX*2+300,-(vis)+100-(Hvis),sX,sY,tocolor (255,255,255,255),2,"default-bold", "center", "center") 
 end 
 end 
 addEventHandler ("onClientRender",root, weaponBar) 

--server 
local luck = math.random(1,5) 
if luck == 1 then 
outputChatBox ("barrel ") 
message = "Barrel" 
triggerClientEvent ( source, "onUpgradeText", source, message ) 
giveMeBarrel () 
elseif luck == 2 then 
message = "Aura" 
triggerClientEvent ( source, "onUpgradeText", source, message ) 
outputChatBox ("you gived AURA(6 sec)") 
giveMeAura() 
elseif luck ==3 then 
message = "Fix" 
triggerClientEvent ( source, "onUpgradeText", source, message ) 
outputChatBox ("you vehicle fixed") 
fixVehicle ()  
elseif luck == 4 then 
message = "Nitro" 
triggerClientEvent ( source, "onUpgradeText", source, message ) 
outputChatBox ("nitro") 
nitro () 
elseif luck == 5 then 
message = "Rocket" 
triggerClientEvent ( source, "onUpgradeText", source, message ) 
outputChatBox (" rocket") 
doShoot() 
end 
  

Posted
local message = "" 
  
addEvent ( "onUpgradeText", true ) 
addEventHandler ( "onUpgradeText", root, 
    function ( msg ) 
        removeEventHandler ( "onClientRender", root, weaponBar ) 
        message = msg 
        addEventHandler ( "onClientRender", root, weaponBar ) 
    end 
) 
  
function weaponBar ( ) 
    dxDrawRectangle (posX*2+300,posY,250,100, tocolor (0,0,0,150)) 
    dxDrawRectangle (posX*2+300,posY,250,Hvis, tocolor (255,255,255,150)) 
    dxDrawText ("Upgrade",posX*2+300,-(vis)+50-(Hvis),sX,sY,tocolor (255,255,255,255),1.5,"default-bold", "center", "center") 
    dxDrawText (message,posX*2+300,-(vis)+100-(Hvis),sX,sY,tocolor (255,255,255,255),2,"default-bold", "center", "center") 
end 

I'm assuming that you have 'posX', 'posY', 'Hvis', 'vis' variables defined already?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)
:cry: so what i need to do?

As I said, what event are you using for your server-side function? 'Cause you didn't post the entire part of that function. Are you sure that source is returning a player element and not something else?

Edit: Forgot to refresh tab :P Solidsnake14 strikes as always :lol:

Edited by Guest

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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