AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ Enums Problem ] (https://forums.alliedmods.net/showthread.php?t=254810)

Xablau 01-06-2015 16:42

[ Enums Problem ]
 
I have problem on enums :/

See my code:

PHP Code:

enum _:p_DataColumns
{
    
max_health
}
new 
p_Datap_DataColumns ][ ClassColumnStruct ] = 
{
    { 
"max_health"Column_Int11 }
}
public 
plugin_init() 
{
    
RegisterHam(Ham_Spawn"player""Player_Spawn"1); 
}
public 
Player_Spawn(id
{
    
client_print(idprint_chat"New HP: %d"p_Data[id][max_health])
}
public 
client_putinserver(id)
{
    
p_Data[id][max_health] = 200


Player_Spawn is not returning the correct value. Why?

Arkshine 01-06-2015 17:04

Re: [ Enums Problem ]
 
If you do that: p_Data[id][max_health] = 200

It means p_Data should be declared like: new p_Data[MAX_PLAYERS][p_DataColumns];

But you declare it with something else.

Xablau 01-06-2015 17:08

Re: [ Enums Problem ]
 
Quote:

Originally Posted by Arkshine (Post 2245749)
If you do that: p_Data[id][max_health] = 200

It means p_Data should be declared like: new p_Data[MAX_PLAYERS][p_DataColumns];

But you declare it with something else.

How do I create a data dictionary and access it in other functions?
Could provide me an example?

Xablau 01-06-2015 17:20

Re: [ Enums Problem ]
 
PHP Code:

enum _:p_DataColumns

    
max_health 

new 
p_Data[33][p_DataColumns]

public 
plugin_init()  

    
RegisterHam(Ham_Spawn"player""Player_Spawn"1);  

public 
Player_Spawn(id)  

    
client_print(idprint_chat"New HP: %d"p_Data[id][max_health]) 

public 
client_putinserver(id

    
p_Data[id][max_health] = 200 


Still not work.
client_print(id, print_chat, "New HP: %d", p_Data[id][max_health]) // Return New HP: 0

Arkshine 01-06-2015 18:49

Re: [ Enums Problem ]
 
Add is_user_alive() in Player_Spawn. Ham_Spawn is called twice, just before you are put in server (you spawn the first time as a player entity, and later alive, after choosing team/class.

Xablau 01-06-2015 19:25

Re: [ Enums Problem ]
 
Quote:

Originally Posted by Arkshine (Post 2245791)
Add is_user_alive() in Player_Spawn. Ham_Spawn is called twice, just before you are put in server (you spawn the first time as a player entity, and later alive, after choosing team/class.

PHP Code:

public Player_Spawn(id)  

    if(
is_user_alive(id)) client_print(idprint_chat"New HP: %d"p_Data[id][max_health]) 


Still not work...
p_Data[id][max_health] is not returning 200

fysiks 01-06-2015 19:36

Re: [ Enums Problem ]
 
Attach your whole running .sma file so we can check it.

fysiks 01-06-2015 20:04

Re: [ Enums Problem ]
 
1 Attachment(s)
The enums works just fine, see this modified version of your plugin (that was changed to test the enum only). Therefore, issue is unrelated to the enum.

Your issue is the sockets. You cannot read from the socket in the same function as you send the socket packet out. The internet is not that fast. Look at the sockets tutorial for how to do it (I actually recently learned how to use sockets from that same tutorial also).

Xablau 01-06-2015 20:10

Re: [ Enums Problem ]
 
i change public client_putinserver(id) to public client_putinserver(pid) and it worked.
How strange. Why?


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

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