Jump to content

Client Script Does Not Work


Vector

Recommended Posts

I have two scripts. The client side script and the server side script.

The server side script is executed, but the client side script not.

Seems that events and event handlers in the client side are not created, so, the function triggerClientEvent has no effect.

here is my meta file -->>

  
[color=#0000FF]<meta>[/color] 
    <[color=#0000FF]info[/color][color=#008080] author[/color]=[color=#FF0040]"__Vector__"[/color] [color=#008080]version[/color]=[color=#FF0040]"1.0"[/color] [color=#008080]description[/color]=[color=#FF0040]"My Script" [/color][color=#008080]type[/color]=[color=#FF0040]"script"[/color] /> 
    <[color=#0000FF]script[/color] [color=#008080]src[/color]=[color=#FF0040]"server.lua"[/color] [color=#008080]type[/color]=[color=#FF0040]"server"[/color] /> 
    <[color=#0000FF]srcipt[/color] [color=#008080]src[/color]=[color=#FF0040]"client.lua"[/color] [color=#008080]type[/color]=[color=#FF0040]"client"[/color] /> 
[color=#0000FF]</meta>[/color] 

server file script ->

server.lua

[color=#0000FF]local[/color] function foo (thePlayer) 
      triggerClientEvent (getRootElement (),[color=#FF0040]"runit"[/color], getRootElement (), thePlayer); 
[color=#0000FF]end;[/color] 
  
addCommandHandler ([color=#FF0040]"run"[/color], foo, [color=#0000FF]false[/color], [color=#0000FF]false[/color]);  
  

client file script ->

client.lua

[color=#0000FF]local[/color] function bar (thePlayer) 
      outputChatBox (getPlayerName (getLocalPlayer ()) .. [color=#FF0040]" receives an event from player "[/color] .. getPlayerName (thePlayer), 
                               getRootElement (), [color=#008080]255[/color], [color=#008080]0[/color], [color=#008080]0[/color]); 
   [color=#00BF00]   -- this does not print nothing[/color]     
[color=#0000FF]end;[/color] 
  
addEvent ([color=#FF0040]"runit"[/color], [color=#0000FF]true[/color]); 
addEventHandler ([color=#FF0040]"runit"[/color], getRootElement (), bar); 

Edited by Guest
Link to comment

Try this:

server.lua

function foo (thePlayer) 
      triggerClientEvent (getRootElement (), "runit", thePlayer); 
end; 
  
addCommandHandler ("run", foo);  
  

client.lua

function bar () 
      outputChatBox (getPlayerName (getLocalPlayer ()) .. " receives an event from player " .. getPlayerName (localPlayer), getRootElement (), 255, 0, 0) 
end; 
addEvent ("runit", true); 
addEventHandler ("runit", getRootElement (), bar); 

thePlayer is not client element.

Link to comment

You need to add the client files before the server files in the 'meta.xml' file.

Try this:

server.lua

function foo (thePlayer) 
      triggerClientEvent (getRootElement (), "runit", thePlayer); 
end; 
  
addCommandHandler ("run", foo);  
  

client.lua

function bar () 
      outputChatBox (getPlayerName (getLocalPlayer ()) .. " receives an event from player " .. getPlayerName (localPlayer), getRootElement (), 255, 0, 0) 
end; 
addEvent ("runit", true); 
addEventHandler ("runit", getRootElement (), bar); 

thePlayer is not client element.

It is passed with triggerClientEvent.

Link to comment

Does not work as well.

According to the mta wiki. the third argument of triggerClientEvent is "The element that is the source of the event. This could be another player, or if this isn't relevant, use the root element." irrelevant. so your code does not remove the error, just assigning to the global variable "source", the variable "thePlayer". But thanks.

Link to comment

nothing happen

meta file =>

  
[color=#0000FF]<meta>[/color] 
    <[color=#0000FF]info[/color][color=#008080] author[/color]=[color=#FF0040]"__Vector__"[/color] [color=#008080]version[/color]=[color=#FF0040]"1.0"[/color] [color=#008080]description[/color]=[color=#FF0040]"My Script" [/color][color=#008080]type[/color]=[color=#FF0040]"script"[/color] /> 
    <[color=#0000FF]script[/color] [color=#008080]src[/color]=[color=#FF0040]"client.lua"[/color] [color=#008080]type[/color]=[color=#FF0040]"client"[/color] /> 
    <[color=#0000FF]srcipt[/color] [color=#008080]src[/color]=[color=#FF0040]"server.lua"[/color] [color=#008080]type[/color]=[color=#FF0040]"server"[/color] /> 
[color=#0000FF]</meta>[/color] 

Link to comment

I tried this code in the client side script and does not work.

Please help.

[color=#0000FF]function[/color] outputPressedCharacter(character) 
    [color=#0000FF]if [/color]character==[color=#FF0040]" "[/color] then [color=#00FF00]--if the character is a space[/color] 
        character = [color=#FF0040]"space"[/color][color=#00FF00] --change 'character' to 'space'[/color] 
    [color=#0000FF]end[/color] 
    outputChatBox([color=#FF0040]"You pressed the character "[/color]..character..[color=#FF0040]"!"[/color]) [color=#00FF00]--output the character[/color] 
[color=#0000FF]end[/color] 
addEventHandler([color=#FF0040]"onClientCharacter"[/color], getRootElement(), outputPressedCharacter) 

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