Thread Closed 
 
Thread Rating:
  • 6 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OnChatUserMessage: crashes if multiple messages appear
Author Message
aclime Offline
Goblin Grave Robber
*

Posts: 12
Joined: May 2012
Reputation: 0
Version: 1.4.1.95
Post: #1
OnChatUserMessage: crashes if multiple messages appear

I created a little script that checks whether someone wrote on the chat. When I use it, it sometimes works, but I noticed that if several messages appear, the plugin crashes.

Code:
function OnChatUserMessage(chatTypechatType, nick, msg)
    if detection1 then
if GetUserByName(nick):IsPlayer() then
PlaySound(GetDir() .. "silent_beep.wav");
ShowToClient("PM Guard1", "///.");
end
    end
    if detection2 then
if GetUserByName(nick):IsPlayer() and chatType == 2 then
PlaySound(GetDir() .. "silent_beep.wav");
ShowToClient("PM Guard2", "///.");
end
    end
end;
detection1 and detection2 are two booleans that control whether I want to check for all messages or only for whispers. ShowToClient is used here just for debugging.
03-17-2013 08:33 AM
Find all posts by this user
ClockMan Offline
All Mighty
*******

Posts: 2,886
Joined: Jan 2011
Reputation: 499
Version: 1.4.3.143
Post: #2
RE: OnChatUserMessage: crashes if multiple messages appear

Add Check if GetUserByName(nick) is not nil

[Image: owner.gif]
03-17-2013 10:28 AM
Visit this user's website Find all posts by this user
aclime Offline
Goblin Grave Robber
*

Posts: 12
Joined: May 2012
Reputation: 0
Version: 1.4.1.95
Post: #3
RE: OnChatUserMessage: crashes if multiple messages appear

Code:
function OnChatUserMessage(chatTypechatType, nick, msg)
    if detection1 then
        if GetUserByName(nick):IsPlayer() and GetUserByName(nick) ~= nil then
            PlaySound(GetDir() .. "silent_beep.wav");
            ShowToClient("PM Guard1", "///.");
        end
    end
    if detection2 then
        if GetUserByName(nick):IsPlayer() and chatType == 2 and GetUserByName(nick) ~= nil then
            PlaySound(GetDir() .. "silent_beep.wav");
            ShowToClient("PM Guard2", "///.");
        end
    end
end;
Works if I write something on the chat. I waited for a minute and two hero messages appeared. The plugin crashed, displayed yellow in the plugins list.
03-17-2013 11:23 AM
Find all posts by this user
Sakaszli Offline
I'm too pro to be pro.
*******

Posts: 1,189
Joined: Jan 2011
Reputation: 484
Version: 1.4.2.134.5b
Post: #4
RE: OnChatUserMessage: crashes if multiple messages appear

if GetUserByName(nick):IsPlayer() and GetUserByName(nick) ~= nil then

ohh god why... it should be:

if GetUserByName(nick) ~= nil and GetUserByName(nick):IsPlayer() then
03-17-2013 13:12 PM
Visit this user's website Find all posts by this user
aclime Offline
Goblin Grave Robber
*

Posts: 12
Joined: May 2012
Reputation: 0
Version: 1.4.1.95
Post: #5
RE: OnChatUserMessage: crashes if multiple messages appear

Sorry, I am not so good at Lua language. What does it actually do if you write GetUserByName(nick) ~= nil? Also, is there a difference in which order you write if statement's conditions?

Seems to work now.
(This post was last modified: 03-17-2013 14:11 PM by aclime.)
03-17-2013 14:11 PM
Find all posts by this user
TheBl4ckPhoenix Offline
(^.^)
****

Posts: 1,887
Joined: Mar 2012
Reputation: 599
Version: 1.4.3.143
Post: #6
RE: OnChatUserMessage: crashes if multiple messages appear

It will First check if the player "exist", if yes it will continue doing its job
03-17-2013 18:21 PM
Find all posts by this user
Thread Closed 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Script that read the chat messages carlosdiegao 7 5,733 12-10-2017 19:15 PM
Last Post: testforl2
  Please help, Tower kept on crashes.... ekin 5 2,656 10-31-2015 19:49 PM
Last Post: mode231
  LF Script for using SS when multiple mobs around olaszosan1 3 2,665 10-29-2014 17:33 PM
Last Post: TheQQmaster
  Multiple start points in goddard/shuttgart? Nertiz1 6 4,758 04-28-2014 12:25 PM
Last Post: knutoz
  running multiple tower accounts (1 VIP, other free)... Simiac 2 2,790 04-19-2014 12:25 PM
Last Post: TheBl4ckPhoenix
  multiple license files kerberos464 2 2,102 12-26-2013 12:50 PM
Last Post: kerberos464
  Best auto Clicker for multiple Windows? dev0 6 5,293 10-04-2013 12:12 PM
Last Post: devling
  buffer client crashes after some minutes oozaoru 7 3,501 08-01-2013 03:56 AM
Last Post: oozaoru
  Often Client Crashes immaxx 12 5,655 10-24-2012 16:41 PM
Last Post: immaxx
  Multiple Bots blabla 6 7,319 04-26-2012 07:39 AM
Last Post: Hebdzik



User(s) browsing this thread: 1 Guest(s)