Jump to content

[HELP] About client, server commands


28WL

Recommended Posts

Please, help me.

If I write that "/extermination" command ---> only I will see it, other players not?

Client script --- Player, who is one the groups, write a command --- only he will see?

Server script --- If somebody one of the groups member will write a command, then all players will see these messages?

And this is client script, nobody will see it, just who wrote it?

addCommandHandler ( "extermination", 
    function ( MissionExtermination ) 
        if isAccountInGroup ( { "Exterminator" "Soldier" }, getAccountName ( getPlayerAccount ( MissionExtermination ) ) ) then 
            outputChatBox("^ ATTENTION WARNING!", MissionExtermination, 255, 0, 0, true) 
            outputChatBox("^ Started mission: Extermination.", MissionExtermination, 255, 0, 0, true) 
        else 
            outputChatBox ("^ You have no acces to that command.", MissionExtermination ) 
        end 
    end 
) 
  
function isAccountInGroup ( groups, account ) 
    local theGroup = false 
    for _, group in ipairs ( groups ) do 
        if isObjectInACLGroup ( "user.".. account, aclGetGroup ( group ) ) then 
            theGroup = group 
            break 
        end 
    end 
    return theGroup 
end 

So I need to create (add) server script?

  
addEvent ( "extermination", true ) 
addEventHandler ( "MissionExtermination", root, 
    function ( MissionExterminationStart ) 
            outputChatBox("^ ATTENTION WARNING!", MissionExterminationStart, 255, 0, 0, true) 
            outputChatBox("^ Started mission: Extermination.", MissionExterminationStart, 255, 0, 0, true) 
    end 
) 

Link to comment

Use

triggerServerEvent 

So instead of the outputChatBox @ the client side, you use

addCommandHandler ( "extermination", 
    function ( MissionExtermination ) 
        if isAccountInGroup ( { "Exterminator" "Soldier" }, getAccountName ( getPlayerAccount ( MissionExtermination ) ) ) then 
            triggerServerEvent("extermination", getRootElement()) 
        else 
            outputChatBox ("^ You have no acces to that command.", MissionExtermination ) 
        end 
    end 
) 
  

Server side fixed;

  
    function output() 
            outputChatBox("^ ATTENTION WARNING!", 255, 0, 0) 
            outputChatBox("^ Started mission: Extermination.", 255, 0, 0) 
    end 
addEvent("extermination", true) 
addEventHandler("extermination", getRootElement(), output) 

Link to comment
  • Moderators

Is incorrect.

addCommandHandler doesn't return a player at client side. That should be the localPlayer.

(localPlayer doesn't have to be defined with the parameters, it is at every place at clientside reach able)

triggerServerEvent("extermination", localPlayer) 

triggerServerEvent("extermination", localPlayer) is source

At serverside the player is:

source -- this is the element of the event handler.(when this is the player) 
or client 

(source doesn't have to be defined with the parameters, nor as client)

@xDrul

You can't just skip an argument of outputChatBox ...... :? ( it is serverside, not client side)

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