Sending a message to admin?
Discussion in 'Rust Development' started by PaiN, Apr 29, 2015.
-
- Loop all players
- if player is an admin
- send message -
I know i know but i want to have an example written
-
- Loop through activePlayerList
- Check if current player has admin flag
- If so send the message, if not continue with next loop
Jakkee already gave you perfect pseudo code, we wont code the plugin for you.
Try converting each pseudo code line into actual code and if you're stuck post your code and we will help you figure out your mistakes but we wont write the plugin for you. -
I did it but
error:
-
Hard to say without seeing the coded, but the indexes start from 0, so player 1 is = 0 and for example 6th player is = 5. So you probably - 1 onlineplayer and loop then
-
Here is the command
Code:function PLUGIN:cmdTest(player, cmd, args)local message = args[1]if (message == nil) then rust.SendChatMessage(player, self.Config.Messages.NoMessage) return end if args[2] then rust.SendChatMessage(player, self.Config.Messages.NoQuotes) return end local onlinePlayerCount = global.BasePlayer.activePlayerList.Count local steamId = rust.UserIDFromPlayer(player) if permission.UserHasPermission(steamId, "cansee") then rust.SendChatMessage(player, self.Config.Settings.ChatName, self.Config.Messages.TestFrom .. " " .. rust.QuoteSafe(player.displayName) .. ": " .. message) else rust.SendChatMessage(player, "No Permission") end end -
Wulf Community Admin
You are trying to use args that don't exist, start with args[0] and increment for each argument.
-
You are trying to use args that don't exist, start with args[0]
..
didnt get it
so local must be "local message = args[0]"? -
Yeah, and you have args[2] there too, so you need to change it to args[1].
But if player just does command /sendadm without anything else, you will probably get an error. So you need to check if there is any arguments or otherwise it will still throw error about Array index out of range
Code:if(args.Length == 0) then -- Send message to player example ("Correct syntax is /sendadm name message") return end -
- Get message from Args
- Save Arg or Args in a variable (e.g: x)
- loop all active players
- If active player is an admin
- send message: (PlayerXYZ said Variable x)
- Else
- Continue loop
Follow this pseudo code.
Its simple, Just trial & error until its working.
-
Got it thanks
