AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get_pcvar_float help (https://forums.alliedmods.net/showthread.php?t=127908)

S34Qu4K3 05-26-2010 10:04

Get_pcvar_float help
 
I have this code:

PHP Code:

/*

    This plugin sets each 30 seconds  a rondom hitzone
    ##CVARS##
    amx_random_hitzones 1//0   (defaut 1)
    amx_random_hitzones_time 30.0


*/
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fun>


new toggle
new hold_time

public plugin_init() 
{
    
register_plugin("Random HitZones""1.1""S34Qu4K3")
    
    
toggle register_cvar("amx_random_hitzones""1")
    
hold_time   register_cvar("amx_random_hitzones_time""10.0")
    
    
RegisterHam(Ham_Spawn"player""Main"1);
    
    
register_dictionary("randomhitzones.txt")
}
public 
Main(id)
{
    if(
get_pcvar_num(toggle))
    {
    new 
rand random_num(0,7)
    switch(
rand)
    {
        case 
0:
        {
            
set_user_hitzones(,0255)
            
client_print(idprint_chat"%L"LANG_PLAYER"GENERIC")
        }
        case 
1:
        {
            
set_user_hitzones(,02)
            
client_print(idprint_chat"%L"LANG_PLAYER"HEAD_ONLY")
        }
        case 
2:
        {
            
set_user_hitzones(,04)
            
client_print(idprint_chat"%L"LANG_PLAYER"CHEST_ONLY")
        }
        case 
3:
        {
            
set_user_hitzones(,08)
            
client_print(idprint_chat"%L"LANG_PLAYER"STOMACH_ONLY")
        }
        case 
4:
        {
            
set_user_hitzones(,016)
            
client_print(idprint_chat"%L"LANG_PLAYER"LEFTARM_ONLY")
        }
        case 
5:
        {
            
set_user_hitzones(,032)
            
client_print(idprint_chat,  "%L"LANG_PLAYER,"RIGHTARM_ONLY")
        }
        case 
6:
        {
            
set_user_hitzones(,064)
            
client_print(idprint_chat,  "%L"LANG_PLAYER"LEFTLEG_ONLY")
        }
        case 
7:
        {
            
set_user_hitzones(,0128)
            
client_print(idprint_chat,  "%L"LANG_PLAYER,"RIGHTLEG_ONLY")
        }
    }
    
set_task(get_cvar_float("hold_time"),"Main")

    }
    else
    {
        
client_print(idprint_chat"%L"LANG_PLAYER"OFF")
    }


BUt I think that this part is bad:

PHP Code:

set_task(get_cvar_float("hold_time"),"Main"

Someone can help me?

Xellath 05-26-2010 10:30

Re: Get_pcvar_float help
 
Code:
set_task(get_pcvar_float(hold_time),"Main")

S34Qu4K3 05-26-2010 10:32

Re: Get_pcvar_float help
 
Yes, solved, now, can you check the code for other errors?

PHP Code:

/*

    This plugin sets each 30 seconds  a rondom hitzone
    ##CVARS##
    amx_random_hitzones 1//0   (defaut 1)
    amx_random_hitzones_time 30.0


*/
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fun>


new toggle
new hold_time

public plugin_init() 
{
    
register_plugin("Random HitZones""1.1""S34Qu4K3")
    
    
toggle register_cvar("amx_random_hitzones""1")
    
hold_time   register_cvar("amx_random_hitzones_time""10.0")
    
    
RegisterHam(Ham_Spawn"player""Main"1);
    
    
register_dictionary("randomhitzones.txt")
}
public 
Main(id)
{
    if(
get_pcvar_num(toggle))
    {
    new 
rand random_num(0,7)
    new 
name[32]
    
get_user_name(idname31)
    switch(
rand)
    {
        case 
0:
        {
            
set_user_hitzones(,0255)
            
client_print(idprint_chat"%L "LANG_PLAYER"GENERIC"name[id])
        }
        case 
1:
        {
            
set_user_hitzones(,02)
            
client_print(idprint_chat"%L"LANG_PLAYER"HEAD_ONLY"name[id])
        }
        case 
2:
        {
            
set_user_hitzones(,04)
            
client_print(idprint_chat"%L"LANG_PLAYER"CHEST_ONLY"name[id])
        }
        case 
3:
        {
            
set_user_hitzones(,08)
            
client_print(idprint_chat"%L"LANG_PLAYER"STOMACH_ONLY"name[id])
        }
        case 
4:
        {
            
set_user_hitzones(,016)
            
client_print(idprint_chat"%L"LANG_PLAYER"LEFTARM_ONLY"name[id])
        }
        case 
5:
        {
            
set_user_hitzones(,032)
            
client_print(idprint_chat,  "%L"LANG_PLAYER,"RIGHTARM_ONLY"name[id])
        }
        case 
6:
        {
            
set_user_hitzones(,064)
            
client_print(idprint_chat,  "%L"LANG_PLAYER"LEFTLEG_ONLY"name[id])
        }
        case 
7:
        {
            
set_user_hitzones(,0128)
            
client_print(idprint_chat,  "%L"LANG_PLAYER,"RIGHTLEG_ONLY"name[id])
        }
    }
    
    
set_task(get_pcvar_float(hold_time),"Main")

    }
    else
    {
        
client_print(idprint_center"%L"LANG_PLAYER"OFF")
    }



Xellath 05-26-2010 10:43

Re: Get_pcvar_float help
 
  • amxmisc isn't used, however, it doesn't matter that it's included.
  • You're printing the text to the player that is spawning - why bother printing their name?
  • You use LANG_PLAYER and since you're printing to id, use id instead of LANG_PLAYER.
  • A thinking entity would be more suitable for this kind of action, as it takes less cpu and memory than a set_task. That is of course if you plan changing them every ten seconds. If you still want the set_task way I'd suggest you to make a task that loops instead of having 32 tasks. 1 task with 32 players > 32 tasks with 32 players

You should check it yourself next time, and if you encounter any difficulties, just ask someone on the forums.

S34Qu4K3 05-26-2010 11:01

Re: Get_pcvar_float help
 
Quote:

Originally Posted by Xellath (Post 1191710)
  • amxmisc isn't used, however, it doesn't matter that it's included.
  • You're printing the text to the player that is spawning - why bother printing their name?
  • You use LANG_PLAYER and since you're printing to id, use id instead of LANG_PLAYER.
  • A thinking entity would be more suitable for this kind of action, as it takes less cpu and memory than a set_task. That is of course if you plan changing them every ten seconds. If you still want the set_task way I'd suggest you to make a task that loops instead of having 32 tasks. 1 task with 32 players > 32 tasks with 32 players

You should check it yourself next time, and if you encounter any difficulties, just ask someone on the forums.

1. ;)
2.Beacause the plugin sets a different hitzone for each player (i donīt know how to set the same hitzone for all the players)
3.Thanks :D
4.I didnīt know hot to do this, iīll be glad if you teach me :D


I will try :D

Xellath 05-26-2010 15:51

Re: Get_pcvar_float help
 
Thinking entity:

Code:
#include < amxmodx > #include < hamsandwich > #include < engine > const Float:INTERVAL = 10.0; new const g_szThinkingEntityClassname[ ] = "hitzone_think"; new g_iThinkingEntity; public plugin_init( ) {     g_iThinkingEntity = create_entity( "info_target" );     entity_set_string( g_iThinkingEntity, EV_SZ_classname, g_szThinkingEntityClassname );     entity_set_float( g_iThinkingEntity, EV_FL_nextthink, INTERVAL );         RegisterHam( Ham_Think, g_szThinkingEntityClassname, "Forward_EntityThink" ); } public Forward_EntityThink( iEntity ) {     static szPlayers[ 32 ], iPlayerCount, iNum, iPlayer;     if( iEntity == g_iThinkingEntity )     {         get_players( szPlayers, iPlayerCount, "a" );         for( iNum = 0; iNum < iPlayerCount; iNum++ )         {             iPlayer = szPlayers[ iNum ];                         // iPlayer = index of a player             // do whatever to set their hitzone here         }     }         entity_set_float( g_iThinkingEntity, EV_FL_nextthink, INTERVAL ); }

Set task:

Code:
#include < amxmodx > const Float:INTERVAL = 10.0; public plugin_init( ) {     set_task( INTERVAL, "HitzoneTask", _, _, _, "b" ); } public HitzoneTask( ) {     static szPlayers[ 32 ], iPlayerCount, iNum, iPlayer;     get_players( szPlayers, iPlayerCount, "a" );     for( iNum = 0; iNum < iPlayerCount; iNum++ )     {         iPlayer = szPlayers[ iNum ];                 // iPlayer = index of a player         // do whatever to set their hitzone here     } }


All times are GMT -4. The time now is 05:20.

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