AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   new round keeps hp (https://forums.alliedmods.net/showthread.php?t=339248)

Nutu_ 08-27-2022 16:26

new round keeps hp
 
hello, Im trying to make a human classes and i was wondering how could i let a player having the same "class" more rounds? i mean, if a player chooses class1 (200hp blabla) but he is able to chose only one class per round, how can i let him continuing the same class even the next round without choosing it again?
PHP Code:

public evHookRoundStart( )
{
    new 
iPlayers32 ];
    new 
iPlayersNum;
    
    
get_playersiPlayersiPlayersNum"ch" );        
    for( new 
iPlayersNum i++ )
    {
        
UserChoosed[iPlayers[i]]  =  false;
    }
    


i have to false the userchoosed to make it work once a round... but i want to let the player keeping the class even in the next round and only next round to be able to change his class! (only if he wants, he can keep the same class every round without having to choose every round)
edit: the main thing i want is that if i choose class1 with 200hp the next round i want to respawn with 200hp again (as my class) not default with 100

deprale 08-27-2022 17:58

Re: new round keeps hp
 
You can define the HP in an enum for each class and then set each accordingly with set_user_health on that hook roundstart.

Nutu_ 08-27-2022 19:15

Re: new round keeps hp
 
Quote:

Originally Posted by deprale (Post 2787552)
You can define the HP in an enum for each class and then set each accordingly with set_user_health on that hook roundstart.

could you send me an example please?

deprale 08-27-2022 23:16

Re: new round keeps hp
 
PHP Code:

#include <amxmodx>
#include <fun>
#include <hamsandwich>

new gChosenClass[MAX_PLAYERS+1]


enum _:Classes
{
    
szClassName[64],
    
iSetHealth
}

new const 
g_Classes[ ][ Classes ] = {
    {
"BATMAN"1555},
    {
"HUMAN"200},
    {
"ZOMBIE"1004},
    {
"TAKTU"9999}
}

public 
plugin_init(){
    
register_plugin("test""0.0.1""none");
    
RegisterHam(Ham_Spawn"player""fwHamPlayerSpawnPost"1
}

public 
fwHamPlayerSpawnPost(id){
    if (!
is_user_connected(id))
        return 
PLUGIN_HANDLED


    gChosenClass
[id] = // TEMPORARY (You should build your own menu for selection, this is solely for demonstrative purposes)

    
switch(gChosenClass[id]){
        case 
0grant(id0)
        case 
1grant(id1)
        case 
2grant(id2)
        case 
3grant(id3)
    }

    return 
PLUGIN_HANDLED;
}

stock grant(idint){
    
set_user_health(idg_Classesint ][ iSetHealth ])
    
client_print(idprint_center"Your class is %s"g_Classes[int][szClassName])


I didn't build a menu since I don't have the time to build one for this demo.

Nutu_ 08-28-2022 05:21

Re: new round keeps hp
 
1st, i want to add more than just hp, speed and gravity too..
2nd, do i have to use spawnpost because i dont want to show the menu everyround to a player..

deprale 08-28-2022 14:29

Re: new round keeps hp
 
Quote:

Originally Posted by Nutu_ (Post 2787576)
1st, i want to add more than just hp, speed and gravity too..
2nd, do i have to use spawnpost because i dont want to show the menu everyround to a player..

Of course you don't have to use spawnpost, and you can just add iSetSpeed and iSetGravity in the enum, then set them in the g_Classes array after the HP, it's scalable! I used spawnpost because it was easier for my example, exactly why I didn't build a whole menu for the demo.

PHP Code:

enum _:Classes
{
    
szClassName[64],
    
iSetHealth,
    
iSetSpeed,
    
iSetGravity
}

new const 
g_Classes[ ][ Classes ] = {
    {
"BATMAN"1555450600}, // This is poor hardcoding practice, I'd suggest defining the classes speed & gravity for each one, so you can easily change them after. #define CLASS_SPEED int #define CLASS_GRAVITY int
    
{"HUMAN"200250800}, // And use them instead of these 'hardcoded' values here, will be more readable and better in long term.
    
{"ZOMBIE"1004500700},
    {
"TAKTU"99991001000}


^ This is poor hardcoding practice, I'd suggest defining the classes speed & gravity for each one, so you can easily change them after.


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

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