AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   can someone help me with this please! (https://forums.alliedmods.net/showthread.php?t=223421)

maximus.toby 08-13-2013 11:22

can someone help me with this please!
 
can someone help me how to code freeze at the end off the round, i alrdy have dropguns at the end of the round, but i want to, so they freeze to for like 1 sec
can someone help me with this Thank alrdy! xx


PHP Code:

#include <amxmodx>
#include <fun>

public plugin_init()
{
    
register_plugin("Drop weapons""1.0""FA");
    
    
register_logevent("round_end"2"1=Round_End");
}

public 
round_end() 

    new 
players[32],inum
    
get_players(players,inum
    for(new 
idid<inum;id++) { 
       if( 
is_user_alive(id) )
    {
        
strip_user_weapons(id); 
        
give_item(id"weapon_knife"); 
    }
    } 



EpicMonkey 08-13-2013 11:42

Re: can someone help me with this please!
 
Go through the posts in this thread: https://forums.alliedmods.net/showthread.php?p=1262605

Black Rose 08-13-2013 18:46

Re: can someone help me with this please!
 
Your code won't work.
You're using get_players but you're completely ignoring the returned array players[].

So if you use get_players() and it will return an array like this:
players[] = { 1, 3, 6, 25 }

And then you loop players like this:
Code:
for(new id; id<inum;id++) {     server_print("%d", id) }
You would get: 0, 1, 2, 3
This would most likely result in a crash because it would try to call functions with players 0 and 2 who don't exist. On top of that, players 6 and 25 would be left out of the loop completely.

But if you use it like this:
Code:
for(new id; id<inum;id++) {     server_print("%d", players[id]) }
You would get: 1, 3, 6, 25

Here's what it should look like:
Code:
#include <amxmodx> #include <fun> public plugin_init() {     register_plugin("Drop weapons", "1.0", "FA");         register_logevent("round_end", 2, "1=Round_End"); } public round_end() {     new players[32],inum;     get_players(players,inum)     for(new id; id<inum;id++) {         if( is_user_alive(players[id]) )         {             strip_user_weapons(players[id]);             give_item(players[id], "weapon_knife");         }     } }

maximus.toby 08-15-2013 06:17

Re: can someone help me with this please!
 
Quote:

Originally Posted by Black Rose (Post 2012513)
Your code won't work.
You're using get_players but you're completely ignoring the returned array players[].

So if you use get_players() and it will return an array like this:
players[] = { 1, 3, 6, 25 }

And then you loop players like this:
Code:
for(new id; id<inum;id++) {     server_print("%d", id) }
You would get: 0, 1, 2, 3
This would most likely result in a crash because it would try to call functions with players 0 and 2 who don't exist. On top of that, players 6 and 25 would be left out of the loop completely.

But if you use it like this:
Code:
for(new id; id<inum;id++) {     server_print("%d", players[id]) }
You would get: 1, 3, 6, 25

Here's what it should look like:
Code:
#include <amxmodx> #include <fun> public plugin_init() {     register_plugin("Drop weapons", "1.0", "FA");         register_logevent("round_end", 2, "1=Round_End"); } public round_end() {     new players[32],inum;     get_players(players,inum)     for(new id; id<inum;id++) {         if( is_user_alive(players[id]) )         {             strip_user_weapons(players[id]);             give_item(players[id], "weapon_knife");         }     } }

Thanks man, your code work perfect, thanks for the help! x


All times are GMT -4. The time now is 15:52.

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