Raised This Month: $51 Target: $400
 12% 

...


Post New Thread Reply   
 
Thread Tools Display Modes
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-15-2021 , 09:48   Re: ExecuteForward
Reply With Quote #11

Quote:
Originally Posted by Cristian505 View Post
Yesssssss! Please help me (
Here this is how the main plugin should look like, it will set players zombie class randomly on each spawn.

Spoiler
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Cristian505
Senior Member
Join Date: Oct 2020
Old 10-15-2021 , 10:11   Re: ExecuteForward
Reply With Quote #12

...

Last edited by Cristian505; 08-10-2022 at 14:17.
Cristian505 is offline
Cristian505
Senior Member
Join Date: Oct 2020
Old 10-15-2021 , 10:13   Re: ExecuteForward
Reply With Quote #13

...

Last edited by Cristian505; 08-10-2022 at 14:17.
Cristian505 is offline
Cristian505
Senior Member
Join Date: Oct 2020
Old 12-18-2021 , 15:57   Re: ExecuteForward
Reply With Quote #14

...

Last edited by Cristian505; 08-10-2022 at 14:17.
Cristian505 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 12-18-2021 , 16:49   Re: ExecuteForward
Reply With Quote #15

Quote:
Originally Posted by Cristian505 View Post
Hello again! How does this code works?

return ( g_zombie_classes_counter-1 )

Why not g_zombie_class_counter - 1?
Why - 1?
From what i know about amxx every 'new x' starts from 0.
So the first register will push the variable +1, but it will return the index of the last created entry.

What it does (in short):
native_register_zm_class() is called
Array is pushed to index 0.
g_zombie_classes_counter++; ( 0 -> 1, this is just to prepare for the NEXT entry )
return 0, because that's what the calling plugin is interested in. 1 is for the next entry, not actually in use yet. But it still has to be done within the function because there's no secondary function.

If you tried to do the increment after the function is done using set_task() that would really give you trouble as everything is called on plugin_init() (for example) and ALL of the set_task() would be executed afterwards. That means that everything would be given the index 0 and then it would increment the variable +n after EVERY registration is done.
Sometimes code is ugly, especially API code. But it works, without any problem. That's the important thing.

You could however start the index at -1, increment it at the beginning of the function. Everything will use the index selected (in the first case "0") and return just that. And at the next call it will increment to 1 before doing anything else.
Note that the function doesn't actually use the variable so it could be incremented anywhere, but it still would have to start at -1 if you're returning the value after it is being incremented.

Code:
new g_zombie_classes_counter = -1;
// ... public native_register_zm_class(plugin, argc) {
    g_zombie_classes_counter++;
    static szZombieName[MAX_ZOMBIE_NAME_CHARS];     get_string(1, szZombieName, charsmax(szZombieName));     if(!szZombieName[0])     {         server_print("Can not register an empty zombie classname!");         return -1;     }     if(g_iZOMBIE_CLASS[0] == -1)     {         arrayset(g_iZOMBIE_CLASS, 0, sizeof g_iZOMBIE_CLASS);     }     ArrayPushString(g_array_zclass_name, szZombieName);
    return g_zombie_classes_counter;
}

In most languages you could (I think) do:
Code:
return g_zombie_classes_counter++;
but in pawn this is broken and will return a memory address or something (I don't actually know but it's not what you would expect).

It's just a matter of personal preference.
__________________

Last edited by Black Rose; 12-18-2021 at 17:02.
Black Rose is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-18-2021 , 20:16   Re: ExecuteForward
Reply With Quote #16

Quote:
In most languages you could (I think) do:

Code:
return g_zombie_classes_counter++;

but in pawn this is broken and will return a memory address or something (I don't actually know but it's not what you would expect).

It's just a matter of personal preference.
This works just fine actually, I use it all the time. It will, however, iterate the number after returning it. It's the same as using:

Code:
g_zombie_classes_counter++; return g_zombie_classes_counter - 1;

If you want to iterate it first, you should do:

Code:
return ++g_zombie_classes_counter;

Which is the same as doing:

Code:
g_zombie_classes_counter++; return g_zombie_classes_counter;
__________________

Last edited by OciXCrom; 12-18-2021 at 20:20.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 12-19-2021 , 04:50   Re: ExecuteForward
Reply With Quote #17

return g_zombie_classes_counter++;

This might look valid but its not, the previous statement means return a value then do the increment but we all know after a return the function code will no longer be executed.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-19-2021 , 06:49   Re: ExecuteForward
Reply With Quote #18

Like I said, it works just fine.

__________________

Last edited by OciXCrom; 12-19-2021 at 06:49.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 12-19-2021 , 11:04   Re: ExecuteForward
Reply With Quote #19

My previous experience:
https://forums.alliedmods.net/showthread.php?t=241630
__________________
Black Rose is offline
Cristian505
Senior Member
Join Date: Oct 2020
Old 12-20-2021 , 17:55   Re: ExecuteForward
Reply With Quote #20

...

Last edited by Cristian505; 08-10-2022 at 14:17.
Cristian505 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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