Skip to content

Commit

Permalink
Expand 'checkvending' script
Browse files Browse the repository at this point in the history
* Added returned values for buying store.
* Made returned values as bitmask. &1 - Vending, &2 - Autotrading, &4 - Buyingstore

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
  • Loading branch information
cydh committed Nov 21, 2014
1 parent 0fd7ba7 commit bbe733e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
31 changes: 21 additions & 10 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3567,24 +3567,35 @@ 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 buyingstore.

This comment has been minimized.

Copy link
@Lemongrass3110

Lemongrass3110 Nov 22, 2014

Member

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 values are bitmask of.

This comment has been minimized.

Copy link
@Lemongrass3110

Lemongrass3110 Nov 22, 2014

Member

The returned value is a bitmask of:

0 = not vending, doesn't have buyingstore, & not autotrading

This comment has been minimized.

Copy link
@Lemongrass3110

Lemongrass3110 Nov 22, 2014

Member

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 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 if Aaron's state

This comment has been minimized.

Copy link
@Lemongrass3110

Lemongrass3110 Nov 22, 2014

Member

-if

.@state = checkvending("Aaron");
if (.@state&1)
mes "Aaron is currently vending!";
if (.@state&2)
mes "Aaron is autotrading!";
if (.@state&4)
mes "Aaron has buying store!";

This comment has been minimized.

Copy link
@Lemongrass3110

Lemongrass3110 Nov 22, 2014

Member

has a buying store


---------------------------------------

*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!";
Expand Down
32 changes: 25 additions & 7 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -15929,19 +15929,37 @@ 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;
if (sd->state.autotrade)

This comment has been minimized.

Copy link
@Lemongrass3110

Lemongrass3110 Nov 22, 2014

Member

"else if" would be good since he cant do both

This comment has been minimized.

Copy link
@cydh

cydh Nov 23, 2014

Author Contributor

u meant with state.buyingstore

ret |= 2;
if (sd->state.buyingstore)
ret |= 4;
script_pushint(st, ret);
}
return SCRIPT_CMD_SUCCESS;
}

Expand Down

2 comments on commit bbe733e

@Lemongrass3110
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you summoned me here:
Please create some entries in const.txt for the bitmask values. I think an enum is no really needed but it would also increase readability.
Also it might be a good idea to switch 2<>4.

@cydh
Copy link
Contributor Author

@cydh cydh commented on bbe733e Nov 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch the 2<>4, well, thought about it, but just don't want break someone's script. but since no official script use it, I will break it. xD

u're the only loyal commentator. where's everyone. @_@
who's again in scripting duty @euphyy @Atemo

Please sign in to comment.