Merge pull request #120 from rathena/script/checkvending

Expand 'checkvending' script
* The returned value is bitmask of &1 - Vending, &2 - Autotrading, &4 - Buyingstore
This commit is contained in:
Cydh Ramdh 2014-11-25 19:04:40 +07:00
commit 4efbffca45
2 changed files with 48 additions and 17 deletions

View File

@ -3567,24 +3567,36 @@ warg and 0 if they don't.
---------------------------------------
*checkvending({"<Player Name>"})
*checkchatting({"<Player Name>"})
Checks if the player is vending or in a chatroom.
Checks if the player is vending or has has a buyingstore. Additionally
it gives you the information whether the player uses autotrade or not.
Name is optional, and defaults to the attached player if omitted.
Return values for 'checkvending' are
0 = not vending
The returned value is bitmask of.
0 = doesn't have a vending or buyingstore (which also means he can't use autotrade)
1 = normal vending
2 = vending using @autotrade
'checkchatting' returns 1 if they are in a chat room, 0 if they are not.
2 = using @autotrade
4 = has a buyingstore
Examples:
//This will check if Aaron is vending, and if so, put a message in front
//of the attached player saying Aaron is vending.
if (checkvending("Aaron"))
//This will check Aaron's state
.@state = checkvending("Aaron");
if (.@state&1)
mes "Aaron is currently vending!";
if (.@state&4)
mes "Aaron has a buying store!";
if (.@state&2)
mes "Aaron is autotrading!";
---------------------------------------
*checkchatting({"<Player Name>"})
Checks if the player is in a chatroom.
Name is optional, and defaults to the attached player if omitted.
Returns 1 if they are in a chat room, 0 if they are not.
Examples:
//This will check if the attached player in a chat room or not.
if (checkchatting())
mes "You are currently in a chat room!";

View File

@ -15929,19 +15929,38 @@ BUILDIN_FUNC(getmonsterinfo)
return SCRIPT_CMD_SUCCESS;
}
BUILDIN_FUNC(checkvending) // check vending [Nab4]
{
/**
* Check player's vending/buyingstore/autotrade state
* checkvending({"<Player Name>"})
* @author [Nab4]
*/
BUILDIN_FUNC(checkvending) {
TBL_PC *sd = NULL;
if(script_hasdata(st,2))
sd = map_nick2sd(script_getstr(st,2));
if (script_hasdata(st,2)) {
if (!(sd = map_nick2sd(script_getstr(st,2)))) {
ShowError("buildin_checkvending: Player '%s' is not online!\n", script_getstr(st,2));
return SCRIPT_CMD_FAILURE;
}
}
else
sd = script_rid2sd(st);
if(sd)
script_pushint(st, sd->state.autotrade ? 2 : sd->state.vending);
else
if (!sd) {
script_pushint(st,0);
return SCRIPT_CMD_SUCCESS;
}
else {
int8 ret = 0;
if (sd->state.vending)
ret = 1;
else if (sd->state.buyingstore)
ret = 4;
if (sd->state.autotrade)
ret |= 2;
script_pushint(st, ret);
}
return SCRIPT_CMD_SUCCESS;
}