AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Q:How to run commands from one plugin out of another plugin? (https://forums.alliedmods.net/showthread.php?t=1166)

RedBaron 04-17-2004 19:47

Q:How to run commands from one plugin out of another plugin?
 
I'm runing the BlattMonster- and the Anticamping-Plugin and instead of slaping the user/player, like in "case 1", I'd like to spawn a monster on the camper, like bbmonster_spawn <monster> <player>, from the BlattMonster-Plugin!!!

How to do??? Any suggestions???

Code:
// a part out of anticamping.sma        ....         } else if (campmeter[id]>100) {             switch(get_cvar_num("anticamping")) {                 case 1: {                     user_slap(id,get_cvar_num("anticamping_healthpunish"))              }                 case 2: {                     set_user_health(id, get_user_health(id) - get_cvar_num("anticamping_healthpunish"))                 }                 case 3: {                     emit_sound(id,CHAN_VOICE,"player/heartbeat1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)        ....

IceMouse[WrG] 04-17-2004 20:56

Execute the command on the server(servercmd(cmd[]), I think)

QwertyAccess 04-17-2004 21:36

well ice you need to specify what to execute too.

RedBaron 04-18-2004 01:15

okay, the command is
Code:
server_cmd(" command ")
and works fine, when I use it like this

server_cmd("bbmonster_spawn agrunt RedBaron")

green = plugincommand
blue = monstername
red = playername

but now I'd like to know, how I get the playername, who is realy camping???
I know there is this cmd
Code:
new playername[32] get_user_name(id, playername, 31)
but its not working for me or I'm doing somthing wrong, I dont know???
I'm to tiered immo to find out! Its 06:15am here in Germany and I'll try later again to solve my problem, but I'd be glad, if someone could help me out in the meanwhile! :wink: 8) Goodnight all and thx for ur help!!!

IceMouse[WrG] 04-18-2004 02:09

Code:
new playername[33]; new cmd[129] get_user_name(id,playername,32); format(cmd,128, "bbmonster_spawn agrunt %s",playername); servercmd(cmd);

RedBaron 04-18-2004 08:55

thx Ice,

it now works pretty well for me, but it must be
Code:
server_cmd(cmd)
and not
Code:
servercmd(cmd)
but what the heck, it works!!! :wink: :lol:

mucho thx

Zor 04-18-2004 09:33

There is no need to format the cammand as the newer versions of amx and amxmodx have built in format:

native server_cmd(const command[],{Float,_}:...);

Which makes the code redundant and bloated.

As for:
Quote:

new playername[32]
get_user_name(id, playername, 31)
The reason it is not working from what I can see is that whomever has called the function is the person identified by id. So if you the admin are calling the amx_killthecampercommand, then the monster will spawn on you! Hehehe...so to be heplful, of which I cannot at the moment, I need to see the full code of the area you are trying to modify...then I can be helpful!

Cheers! and Luck!

RedBaron 04-18-2004 10:59

huh, Zor??? :shock:

This works just fine for me!!! :up: :mrgreen:
Code:
new playername[33]; new cmd[129] get_user_name(id,playername,32); format(cmd,128, "bbmonster_spawn agrunt %s",playername); server_cmd(cmd);
I dont know what u mean??? :(

IceMouse[WrG] 04-18-2004 12:40

Zor, call me old fashoned, then, but way back when thats how we did it!

Zor 04-18-2004 16:46

No matter, thats just bloat but if it works good to go...didn't know you had solved it. And IceMouse[WrG], soakay we all begin somewhere! :wink: Anyway its because ppl wanted this ability without having to format a string that the code went this way, but as I say, its just easier now.

Cheers!

Johnny got his gun 04-18-2004 17:01

If you want to run functions residing in other plugins:

Code:
/* Call a function in this / an another plugin by name. * Parameters: *  plugin - plugin name; if "", the caller plugin is used. *           If specified, it has to be the exact name (for example stats.amx) *  func   - function name * Return value: *   1     - Success *   0     - Runtime error *  -1     - Plugin not found *  -2     - Function not found */ native callfunc_begin(const plugin[]="", const func[]); /* Push a parameter (integer, string, float) */ native callfunc_push_int(value); native callfunc_push_str(value[]); native callfunc_push_float(Float: value); native callfunc_push_intrf(&value); native callfunc_push_floatrf(& Float: value);

IceMouse[WrG] 04-18-2004 17:50

It would be nice to note that (I'm pretty sure) you must push the values BEFORE calling the function

AssKicR 04-18-2004 18:42

Jonny u forgot

Code:
/* Make the actual call. * Return value of the function called. */ native callfunc_end();

IceMouse[WrG] 04-18-2004 18:58

Alright.. Then you push the vars inbetween callfunc_begin() and callfunc_end()

RedBaron 04-18-2004 20:39

Okay guys,

so, how would the code look like with

bbmonster_spawn agrunt RedBaron

green = plugincommand
blue = monstername
red = playername

but the monster- and playername should be variable!?!?!?

P.S.: If someone wants to see how the "advanced" AntiCampingplugin works, just give me a PM!!! :wink: 8)

IceMouse[WrG] 04-18-2004 20:45

Well since Zor is so picky:
Code:
new playername[33]; get_user_name(id,playername,32); new monstername[33]; switch(random_num(1,2)) {     case 1: strcpy(monstername,"agrunt",33);     case 2: strcpy(monstername,"hassassin",33); } server_cmd("bbmonster_spawn %s %s",monstername,playername);
(Don't rely on those being correct functions)


All times are GMT -4. The time now is 07:03.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.