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

Solved Player bool


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
warps013
Junior Member
Join Date: May 2018
Old 07-03-2018 , 10:36   Player bool
Reply With Quote #1

Hi, I'm trying to find out something like how to set a bool for a specific player. I'm goint to show you my code to have a basic idea of what I want todo, also I know code is totally wrong. So please try to solve just this question. How could I define a "race_creator" for a player an there only can be 1 "race_creator"

PHP Code:
#include <amxmodx> 
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <prokreedz>

new bool:timer_started[32
new 
Float:timer[32
new 
bool:race_status false
const race_players 0
new bool:race_creator false
new bool:race_winner false


public plugin_init() { 
 
register_plugin("TEMP.kz""0.3""warps");
 
set_task(0.1,"timer_task",20000,"",0,"ab") ;
 
register_clcmd("go","startcmd"); 
 
register_clcmd("zz","stopcmd"); 
 
register_clcmd"say /checkmenu""cmdMenu" );
 
RegisterHam(Ham_Use"func_button""hamUse");
 
register_clcmd("say /carrera" "racecmd");
 
register_clcmd("say /ingresar""joincmd");
}
//NATIVES

//TAIMER TASK 
public timer_task() { 
 for(new 
i=1;i<=get_maxplayers();i++) { 
     if(
is_user_alive(i) && timer_started[i-1]) { 
         new 
Float:sec get_gametime() - timer[i-1], min 
         
if((sec 60.0) >= 1) { 
             
min floatround(sec 60.0,floatround_floor
             
sec -= min 60 
         

         
client_print(iprint_center "%d : %f",min ,sec
             
     } 



public 
startcmd(id) {
 
timer[id-1] = 0.0
 timer_started
[id-1] = true;
 
timer[id-1] = get_gametime() 

public 
stopcmd(id

    if(
timer_started[id-1])
    {
        new  
min 
        
new Float:sec get_gametime() - timer[id-1
        if((
sec 60.0) >= 1
        { 
            
min floatround(sec 60.0,floatround_floor
            
sec -= min 60 
        

        
client_print(idprint_center"Tiempo Total: %02d:%02d",min ,sec)
        
timer_started[id-1] = false
    
}
}
//BOTON STOP
public hamUse(entid) {
    if(!(
<= id <= get_maxplayers())) return HAM_IGNORED;
    
    new 
szTarget[32];
    
pev(entpev_targetszTarget31);
    
        if(
equal(szTarget"counter_off") || equal(szTarget"clockstopbutton") || equal(szTarget"clockstop") || equal(szTarget"stop_counter")) { 
        
stopcmd(id)
        }
        
timer_started[id] = false;
        return 
HAM_IGNORED;
    }
//MENU
public cmdMenu(id)
{
    new 
gMenu menu_create("\rRun Menu""handlerMenu")
    
menu_additem(gMenu"\wStart""1")
    
menu_additem(gMenu"\wRace Players""2"
    
menu_additem(gMenu"\wRace Status""3")
    
menu_additem(gMenu"\wRace Creator""4")
    
menu_display(idgMenu0)
   }

public 
handlerMenu(idmenuitem)        
{
    if ( 
item == MENU_EXIT )   
    {
        
menu_destroy(menu)       
        return 
PLUGIN_HANDLED;    
    }
    switch(
item)    
    {
        case 
0:        
{
    if(
id,race_players >= 2){
    
startcmd(id)
    
timer_started[id] = false;
}
else{
    
client_print(id,print_chat,"No tienes acceso a este comando")
}
}
}
    switch(
item)
    {
    case 
1:
    {
    
client_print(id,print_chat,"Race Players = %d",race_players)
}
}
    switch(
item)
    {
    case 
2:
    {
    if(
id,race_creator == true){
    
client_print(id,print_chat,"Race Creator = True")
}
    else{
    
client_print(id,print_chat,"Race Creator = False")
}
}
}
    switch(
item)
    {
    case 
3:
    {
    if(
id,race_status == true){
    
client_print(id,print_chat,"Race Status = True")
}
    else{
    
client_print(id,print_chat,"Race Status = False")
}
}
}
}
//CARRERA
public racecmd(id){        
    
race_status true;
    
cmdMenu(id)
    
race_creator true;
    if(
race_creator == truerace_status == true){
        
client_print(id,print_chat,"Ya hay una carrera en progreso")
    }
}
//CORREDORES
public joincmd(id){
    if(
id,race_status == true)
    
race_players 1
}
//DESCONEXION
public client_disconnect(id){
    
race_players 1



So I know I have to fix a lot the structure of the plugin, but first I want to know that. Thanks!

Last edited by warps013; 07-03-2018 at 11:36.
warps013 is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 07-03-2018 , 10:41   Re: Player bool
Reply With Quote #2

Variant A:

new bool:race_creator => new bool:race_creator[33]

how to get specified players race_creator?
use race_creator[id] and not race_creator
how to set specified players race_creator?
race_creator[id] = X

Variant B (Because its bool, you can also use bit sums):

new race_creator

how to get specified players race_creator?
if (race_creator & (1 << id))
how to set specified players race_creator?
race_creator |= (1 << id)
how to remove specified players race_creator?
race_creator &= ~(1 << id)

(Believe me, first one is easier)
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 07-03-2018 at 10:46.
Ghosted is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-03-2018 , 11:14   Re: Player bool
Reply With Quote #3

I'm not going to look at the entire code, but I want to let you know that instead of using 32 as an array size in the global variables, you should be using 33. The way you have it right now, the 32nd player will break the plugin.

timer_started[32] => timer_started[33]

Btw, this bool is already an example of what you're trying to do.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
warps013
Junior Member
Join Date: May 2018
Old 07-03-2018 , 11:36   Re: Player bool
Reply With Quote #4

Yes, now that you mentioned it you are right. Since I copy that part I didn't noticed it.
Thanks both for the help, also I'm going to change it to 33.

Last edited by warps013; 07-03-2018 at 11:38.
warps013 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-03-2018 , 19:00   Re: Player bool
Reply With Quote #5

Also, use [id], not [id-1].
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 07-04-2018 , 03:43   Re: Player bool
Reply With Quote #6

[32] & id-1 => the best way to shorten memory with 4 bytes.
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 07-04-2018 at 03:44.
Ghosted is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-04-2018 , 08:04   Re: Player bool
Reply With Quote #7

Quote:
Originally Posted by Ghosted View Post
[32] & id-1 => the best way to shorten memory with 4 bytes.
And the server with 2 players.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
warps013
Junior Member
Join Date: May 2018
Old 07-04-2018 , 12:39   Re: Player bool
Reply With Quote #8

So far, this is how code looks like
PHP Code:
#include <amxmodx> 
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <prokreedz>

new Float:timer[32

new 
bool:timer_started[32
new 
bool:race_creator [33]
new 
bool:race_player [33]
new 
bool:race_winner false
new bool:race_status false

new race_players 0


public plugin_init() { 
 
register_plugin("TEMP.kz""0.3""warps");
 
set_task(0.1,"timer_task",20000,"",0,"ab") ;
 
register_clcmd("go","startcmd"); 
 
register_clcmd("zz","stopcmd"); 
 
register_clcmd"say /run""cmdMenu" );
 
RegisterHam(Ham_Use"func_button""hamUse");
 
register_clcmd("say /carrera""racecmd")
 
register_clcmd("say /ingresar""joincmd")
 
register_clcmd("say /info""infocmd")
 
register_clcmd("ganadorcmd""winnercmd")
}
//NATIVES

//TAIMER TASK 
public timer_task() { 
 for(new 
i=1;i<=get_maxplayers();i++) { 
     if(
is_user_alive(i) && timer_started[i-1]) { 
         new 
Float:sec get_gametime() - timer[i-1], min 
         
if((sec 60.0) >= 1) { 
             
min floatround(sec 60.0,floatround_floor
             
sec -= min 60 
         

         
client_print(iprint_center "%d : %f",min ,sec)              
     } 



public 
startcmd(id) {
timer[id-1] = 0.0
 timer_started
[id-1] = true 
 timer
[id-1] = get_gametime() 

public 
stopcmd(id

    if(
race_status == true,timer_started[id-1])
    {
        new  
min 
        
new Float:sec get_gametime() - timer[id-1
        if((
sec 60.0) >= 1
        { 
            
min floatround(sec 60.0,floatround_floor
            
sec -= min 60 
        

        
client_print(idprint_center"Tiempo Total: %02d:%02d",min ,sec)
        
timer_started[id-1] = false
    
}
}
//BOTON STOP
public hamUse(entid) {
    if(!(
<= id <= get_maxplayers())) return HAM_IGNORED;
    
    new 
szTarget[32];
    
pev(entpev_targetszTarget31);
    
        if(
equal(szTarget"counter_off") || equal(szTarget"clockstopbutton") || equal(szTarget"clockstop") || equal(szTarget"stop_counter")) { 
        
stopcmd(id)
        }
        
timer_started[id] = false;
        return 
HAM_IGNORED;
    }
//MENU
public cmdMenu(id)
{
    new 
gMenu menu_create("\rRun Menu""handlerMenu")
    
menu_additem(gMenu"\wStart""1")                                           
    
menu_display(idgMenu0)
   }

public 
handlerMenu(idmenuitem)        
{
    if ( 
item == MENU_EXIT )   
    {
        
menu_destroy(menu)       
        return 
PLUGIN_HANDLED;    
    }
    switch(
item)    
    {
        case 
0:        
{
    if(
race_status == truerace_creator[id] == truerace_players >= 2){
        
startcmd(id)
    }
    else{
        
client_print(id,print_chat,"No es posible empezar la carrera en este momento")
    }
}
}
}
//CARRERA
public racecmd(id){
    if(
race_status == false){
        
race_status true
        race_creator
[id] = true
        race_winner 
false
        client_print
(id,print_chat,"Has creado una carrera")
    }
    else{
        
client_print(id,print_chat,"Una carrera ya ha sido creada")
        
race_creator [id] = false
    
}
}
//INFORMACION CREADOR Y JUGADORES
public infocmd(id){
    
client_print(id,print_chat,"Corredores inscriptos %d"race_players)
    if(
race_creator[id] == true){
        
client_print(id,print_chat,"Eres el creador de la carrera")
    }
    else{
        
client_print(id,print_chat,"No eres creador de la carrera")
    }
}
//CORREDORES
public joincmd(id){
    if(
race_status == true){
        
race_player[id] = true
        client_print
(id,print_chat,"Has ingresado a la carrarera")
        
race_players ++
    }
    else{
        
race_player[id] = false
        client_print
(id,print_chat,"No hay ninguna carrera activa")
    }
}
//GANADOR
public winnercmd(id){
}
//DESCONEXION
public client_disconnect(id){
    if(
race_player[id] == true){
        
race_player[id] = false
        race_players 
race_players 1
    
}
    else if(
race_creator[id] == true){
        
race_creator[id] = false
        race_status 
false
        client_print
(id,print_chat,"La carrera se ha disuelto")
    }

I'm going to take a nap now, later will work on race_winner and add a chatcolor module
warps013 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-04-2018 , 12:49   Re: Player bool
Reply With Quote #9

PHP Code:
new Float:timer[32
33.

PHP Code:
set_task(0.1,"timer_task",20000,"",0,"ab"
Using flags a and b at the same time doesn't make sense.

PHP Code:
for(new i=1;i<=get_maxplayers();i++) 
Don't loop players like this. Use get_players().

PHP Code:
if(is_user_alive(i) && timer_started[i-1]) { 
You're still using [id-1].

PHP Code:
if(race_status == true,timer_started[id-1]) 
This won't even compile.

I'm not going to look further since you probably didn't fix everything yet.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
warps013
Junior Member
Join Date: May 2018
Old 07-04-2018 , 12:58   Re: Player bool
Reply With Quote #10

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Warning: Loose indentation on line 48
Warning: Loose indentation on line 64
Warning: Loose indentation on line 77
Warning: Function "handlerMenu" should return a value on line 107
Warning: Symbol is assigned a value that is never used: "race_winner" on line 159
Header size: 960 bytes
Code size: 5140 bytes
Data size: 2824 bytes
Stack/heap size: 16384 bytes; estimated max. usage=57 cells (228 bytes)
Total requirements: 25308 bytes

5 Warnings.
Done.

So I tried to change it to 33 and delete [id-1] but there was some errors so place them like before (like now)

PHP Code:
if(is_user_alive(i) && timer_started[i-1]) { 
Im using i here not id

Ok, I will try get_players, thanks! Later
warps013 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 17:14.


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