|
08-20-2012
|
23
|
|
Registered User
Join Date: Aug 2011
Location: En La Caja
Posts: 1,679
|
Hey,
Got bored a bit, and don't know what to add to the scripts I made a while back. so having you guys give me an opinion would help. Also, I'm still at a learning stage to any developer feel free to correct me/teach me anything new or give me idea's or other ways to do the certain thing.
Echo from NC (Made while learning triggerserver) - Current usage by saying "/echo TextGoesHere"
- Can echo from the player's chat to RC
- Anti-Spam built (yes, I know timevar2 but I have thought of a different way)
PHP Code:
function onActionServerSide() { if (params[0] == "cmd") { this.toks = player.chat.substring(6); echo(player.nick @ " [" @ player.account @ "] : " @ this.toks); } }
//#CLIENTSIDE function onCreated() { this.num = 1; }
function onPlayerChats() { if (player.chat.starts("/echo")) { if (this.num == 1) { this.toks = player.chat.substring(6); triggerserver("gui", name, "cmd"); sleep(0.1); this.num = 0; setTimer(0.01); player.chat = "Echo'ed : " @ player.chat.substring(6); } else player.chat = "Please wait 5 seconds before sending another Echo!"; } }
function onTimeOut() { if (this.num == 0) { sleep(5); this.num = 1; } setTimer(0.1); }
|
- Just declare a flag as you go, no need for it to be under onCreated()

- When checking for a flag, you can just do if (flag == true)
- Seeing as that you're only using a timer for one thing in the script, don't have your timer set to 0.1, but rather 5 and don't have it loop within onTimeOut.
- Using format(string, var, var) is very nice when using multiple variables to output to a string.
Fixed Version:
Spoiler
PHP Code:
function onActionServerSide() { if (params[0] == "cmd") { this.toks = player.chat.substring(6); echo(format("%s [%s] : %s", player.nick, player.account, this.toks); } }
//#CLIENTSIDE function onPlayerChats() { if (player.chat.starts("/echo")) { if (this.num == false) { this.toks = player.chat.substring(6); triggerserver("gui", name, "cmd"); sleep(0.1); this.num = true; setTimer(5); player.chat = "Echo'ed : " @ player.chat.substring(6); } else player.chat = "Please wait 5 seconds before sending another Echo!"; } }
function onTimeOut() { if (this.num == true) this.num == false; }
Hopefully I could teach some neat ways to expand your scripting in this post!
|
|
|
|