Adding an Attack Slot to ESF

Active Member
✔️ HL Verified
💻 Oldtimer
Joined
Mar 13, 2005
Messages
3,877
Best answers
0
So I have been looking for an hour through all the files and searching for it but couldn't find it.

How would you add an Attackslot in ESF to give say Vegeta a custom coded attack?
 
NOT IN THE MANGA™
★ Black Lounger ★
✔️ HL Verified
🚂 Steam Linked
💻 Oldtimer
Joined
Jan 5, 2008
Messages
3,276
Best answers
0
Location
Lithuania
Never tried myself though I'd like to know also. Did you try to do something about "WeapUpdate" message?

This is what I've been using in order to catch what argumens means what in any message:
Code:
#include <amxmodx>

new const Message[] = \"WeapUpdate\" // Change this to whatever message you want

public plugin_init()
	register_message(get_user_msgid(Message), \"Message\");

public Message(const Message, const Destination, const Entity)
{
	server_print(\"----------\");
	server_print(\"Message = %d\", Message);
	server_print(\"Destination = %d\", Destination);
	server_print(\"Entity = %d\", Entity);

	static Argument, Arguments;
	Arguments = get_msg_args();

	for (Argument = 1; Argument <= Arguments; Argument++) switch (get_msg_argtype(Argument))
	{
		case ARG_BYTE: server_print(\"Argument %d (byte) = %d\", Argument, get_msg_arg_int(Argument));
		case ARG_CHAR: server_print(\"Argument %d (char) = %d\", Argument, get_msg_arg_int(Argument));
		case ARG_SHORT: server_print(\"Argument %d (short) = %d\", Argument, get_msg_arg_int(Argument));
		case ARG_LONG: server_print(\"Argument %d (long) = %d\", Argument, get_msg_arg_int(Argument));
		case ARG_ANGLE: server_print(\"Argument %d (angle) = %f\", Argument, get_msg_arg_float(Argument));
		case ARG_COORD: server_print(\"Argument %d (coord) = %f\", Argument, get_msg_arg_float(Argument));
		case ARG_STRING:
		{
			static String[32];
			get_msg_arg_string(Argument, String, 31);

			server_print(\"Argument %d (string) = ^\"%s^\"\", Argument, String);
		}
		case ARG_ENTITY: server_print(\"Argument %d (entity) = %d\", Argument, get_msg_arg_int(Argument));
	}
}
It would be a good idea to use logs but whatever.

I wonder why vBulletin destroys the code with those slashes... http://ampaste.net/f61ed257f.
 
Last edited:
Freelance Mappzor
✔️ HL Verified
🚂 Steam Linked
💻 Oldtimer
Joined
Nov 21, 2003
Messages
17,065
Best answers
0
Location
Stairing at the Abyss
Well you gove vegeta a Kamehameha and change its sprites and properties. Custom attack made. Thats how ECX handles most of them ^^
 
NOT IN THE MANGA™
★ Black Lounger ★
✔️ HL Verified
🚂 Steam Linked
💻 Oldtimer
Joined
Jan 5, 2008
Messages
3,276
Best answers
0
Location
Lithuania
I thought he wanted to give the attack in a specific slot.
 
Active Member
✔️ HL Verified
💻 Oldtimer
Joined
Nov 6, 2004
Messages
3,055
Best answers
0
Location
Round Rock, TX
Code:
new const Message[] = \"WeapUpdate\";
You shouldn't allocate global memory for one-time use. This memory will be allocated throughout the entire runtime of the plugin, but is only used a single time in plugin_init().

Code:
server_print(\"----------\");
server_print(\"Message = %d\", Message);
server_print(\"Destination = %d\", Destination);
server_print(\"Entity = %d\", Entity);
This uses more CPU than is necessary (four separate native calls), and makes four separate entries in the DAT table. Do this instead:

Code:
server_print(\"----------^nMessage: %d^nDestination: %d^nEntity: %d\", Message, Destination, Entity)
Your for loop is slightly flawed:

Code:
Argument <= get_msg_args();
Cache get_msg_args() before the loop so you don't run it with each pass.

Code:
static Argument,  iArgNum = get_msg_args()
Code:
for (Argument = 1; Argument <= iArgNum; Argument++)
I'm also fairly certain Deathshot isn't a coder, and is looking for an answer more in layman's terms. Grega gave a better answer.
 
NOT IN THE MANGA™
★ Black Lounger ★
✔️ HL Verified
🚂 Steam Linked
💻 Oldtimer
Joined
Jan 5, 2008
Messages
3,276
Best answers
0
Location
Lithuania
I made that constant only for Deathshot, so it would be easier to change that if he ever uses this code.

And you're right about get_msg_args(). The code is pretty old though, if I were to write it again, it would have been better. Never had any problems with that one on my lame PC though.
 
Last edited:
ESF Coder
🌠 Staff
Joined
Jun 13, 2004
Messages
585
Best answers
0
Location
Austria -> Vienna
Well you gove vegeta a Kamehameha and change its sprites and properties. Custom attack made. Thats how ECX handles most of them ^^
Well thats true for the normal attacks, but for things like the specials you have to create custom weapons with its own logic ( inkluding +attack +attack2 )
 
Active Member
✔️ HL Verified
💻 Oldtimer
Joined
Nov 6, 2004
Messages
3,055
Best answers
0
Location
Round Rock, TX
Then use:

Code:
#define MSG_HOOK \"WeapUpdate\"
If you're only using it once, a string macro is infinitely better than caching the value.
 
NOT IN THE MANGA™
★ Black Lounger ★
✔️ HL Verified
🚂 Steam Linked
💻 Oldtimer
Joined
Jan 5, 2008
Messages
3,276
Best answers
0
Location
Lithuania
I see. I was avoiding using definitions for strings.
 
Active Member
✔️ HL Verified
💻 Oldtimer
Joined
Nov 6, 2004
Messages
3,055
Best answers
0
Location
Round Rock, TX
It's better as long as you don't use the macro more than once in your code, as every use of a string macro creates a separate entry in the DAT table. If you need that value more than once in your code, new const is more efficient.
 
ESF Coder
🌠 Staff
Joined
Jun 13, 2004
Messages
585
Best answers
0
Location
Austria -> Vienna
Then use:

Code:
#define MSG_HOOK \\\\"WeapUpdate\\\\"
If you're only using it once, a string macro is infinitely better than caching the value.
wtf?
a variable is better...
during load "WeapUpdate" will be written into the variable which means it will be only 1 time in RAM
if you use a MAKRO it will be as often in RAM as you are using the makro.

makro: (will be created everytime + reference) * usage count
variable: will be created + (reference * usage count)

so using it 1 time = its the same
using it > 1 = variable is better
so variable is better

the same goes for saving this data in the amxx file
 
Last edited:
Active Member
✔️ HL Verified
💻 Oldtimer
Joined
Mar 13, 2005
Messages
3,877
Best answers
0
Pretty much I wanted to add it on the list at the bottom with Kamehameha, Spirit bomb, and all of that. Scroll with the mouse to use it.
 
Member
✔️ HL Verified
Discord Member
Joined
Oct 16, 2006
Messages
379
Best answers
0
Location
the Netherlands
Loving these coder 'battles'.
I don't see why you should use a variable or declaration in the first place for hooking, except when you're testing concepts like now.
 
NOT IN THE MANGA™
★ Black Lounger ★
✔️ HL Verified
🚂 Steam Linked
💻 Oldtimer
Joined
Jan 5, 2008
Messages
3,276
Best answers
0
Location
Lithuania
Loving these coder 'battles'.
I don't see why you should use a variable or declaration in the first place for hooking, except when you're testing concepts like now.
For your code's readability.
 
NOT IN THE MANGA™
★ Black Lounger ★
✔️ HL Verified
🚂 Steam Linked
💻 Oldtimer
Joined
Jan 5, 2008
Messages
3,276
Best answers
0
Location
Lithuania
if you've written it yourself, then you should read it without any problems :)
Exactly, you can read your own code without any problems.
 
Base belongs to me.
👑 Administrator
🌠 Staff
✔️ HL Verified
🚂 Steam Linked
💎Légéñdārý
Joined
Nov 30, 2002
Messages
10,861
Best answers
0
Location
Netherlands
#include <amxmodx>

new const Message[] = "WeapUpdate"; // Change this to whatever message you want

public plugin_init()
register_message(get_user_msgid(Message), "Message");

public Message(const Message, const Destination, const Entity)
{
server_print("----------");
server_print("Message = %d", Message);
server_print("Destination = %d", Destination);
server_print("Entity = %d", Entity);

static Argument;

for (Argument = 1; Argument <= get_msg_args(); Argument++) switch (get_msg_argtype(Argument))
{
case ARG_BYTE: server_print("Argument %d (byte) = %d", Argument, get_msg_arg_int(Argument));
case ARG_CHAR: server_print("Argument %d (char) = %d", Argument, get_msg_arg_int(Argument));
case ARG_SHORT: server_print("Argument %d (short) = %d", Argument, get_msg_arg_int(Argument));
case ARG_LONG: server_print("Argument %d (long) = %d", Argument, get_msg_arg_int(Argument));
case ARG_ANGLE: server_print("Argument %d (angle) = %f", Argument, get_msg_arg_float(Argument));
case ARG_COORD: server_print("Argument %d (coord) = %f", Argument, get_msg_arg_float(Argument));
case ARG_STRING:
{
static String[32];
get_msg_arg_string(Argument, String, 31);

server_print("Argument %d (string) = ^"%s^"", Argument, String);
}
case ARG_ENTITY: server_print("Argument %d (entity) = %d", Argument, get_msg_arg_int(Argument));
}
}
 

Users who are viewing this thread

Top Bottom