clif->ShowScript doubt and retVal question

evilpuncker

vai se tratar garota
Messages
2,178
Points
0
Age
109
Location
bronzil
Github
EPuncker
Emulator
Client Version
2019-05-30a MAIN
Hello everyone! thanks for stopping by. I have zero source/programing knowledge but I was able to make this code to work (yes, it works), but there are two things bothering me:

  1. the clif->ShowScript part works but its throw a warning when compiling
    the warning is: 
    warning C4133: 'function': incompatible types - from 'map_session_data *' to 'block_list *'
  2. the return retVal; that I commented out and changed it to return true;, is it okay? I made these changes to old code following these changes to make the code work on newer hercules


(yes I know I can ignore warnings, but maybe its something really easy that I'm missing and can be fixed)

this is the code:

bool filter_chat(struct map_session_data **sd, const char **message_)
{
const char* message = *message_;

unsigned int i;
char output[254]; // Compiler supposed to reuse the pre-allocated space but who knows, those few bytes doesn't worth lowering the speed.

if (!message)
return false;

if (!mannersize || pc_has_permission(*sd, bypass_chat_filter) || !pc->can_talk(*sd))
//return retVal;
return true;

for (i = 0; i < mannersize; ++i) {
if (libpcre->exec(mannerlist.regex, mannerlist.extra, message, (int)strlen(message), 0, 0, NULL, 0) != PCRE_ERROR_NOMATCH) {
sprintf(output, "i've been saying bad stuff");
clif->messagecolor_self((*sd)->fd, COLOR_RED, output);
clif->ShowScript(*sd, "watch out for your mouth", AREA);
hookStop();
return false;
}
}

return true;
}




its part of this plugin (the lite version)

 
Hello there, i'm not an expert but i'm gonna try to help.
1. About your warning, i got zero errors compiling your plugin in linux so i have no idea why it gives you the warning.
2. Since now you are using a preHook, you don't need to use **retVal**. This is only used when it's a postHook, because sometimes you want to know the returned value from the original execution (for example... stop your hook if you need it when returning an error).

Is it your "little version" related to the warning, or there's more code somewhere?

 
Last edited by a moderator:
Hello there, i'm not an expert but i'm gonna try to help.
1. About your warning, i got zero errors compiling your plugin in linux so i have no idea why it gives you the warning.
2. Since now you are using a preHook, you don't need to use **retVal**. This is only used when it's a postHook, because sometimes you want to know the returned value from the original execution (for example... stop your hook if you need it when returning an error).

Is it your "little version" related to the warning, or there's more code somewhere?


thanks! the "full" code is here on this paste (its missing the showScript part thought)

so I can just remove these three lines? since now the code is using preHook

if (!mannersize || pc_has_permission(*sd, bypass_chat_filter) || !pc->can_talk(*sd))
//return retVal;
return true;




yeah I forgot to say my OS is windows, this is the warning:

Wkgq4pg.png


when I click the warning it sends the cursor directly to the *sd part

 
Last edited by a moderator:
I guess you have been passing the wrong struct to ShowScript function, use this instead : (as you can see here)

clif->ShowScript(&(*sd)->bl, "your message", AREA);


About deleting that conditional... You shouldn't do it if the original function is not gonna be executed ever, not sure about this specific case, and keep in note that when using preHook your function is gonna be executed first.

 
Last edited by a moderator:
Back
Top