AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Variable (array?) trouble... (https://forums.alliedmods.net/showthread.php?t=63261)

BigDontCry 11-16-2007 06:18

Variable (array?) trouble...
 
Hey.

What I'm trying to do is this:
PHP Code:

#define MAX_PLAYERS 33
#define TOTAL_RACES 5
 
new g_PlayerXP[MAX_PLAYERS][TOTAL_RACES]
new 
g_PlayerLevel[MAX_PLAYERS][TOTAL_RACES

...and when I try this for example:
PHP Code:

g_PlayerXP[id][3] = 200
client_print
(idprint_chat"XP: %d"g_PlayerXP[id][3]) 

It just returns 0 when I try to print it on screen...

Suggestions?

BigDontCry 11-16-2007 12:04

Re: Variable (array?) trouble...
 
PHP Code:

public show_player_stats(id) {
 
 new 
bool:lvled false
 
new g_Pl_Race g_PlayerRace[id]
 
 if(
g_PlayerXP[id][g_Pl_Race] < 0) {
  
g_PlayerXP[id][g_Pl_Race] = 0
 
}
 
 if((
g_PlayerLevel[id][g_Pl_Race] < (MAX_LEVEL-1)) && (g_PlayerXP[id][g_Pl_Race] >= xplevel_lev[g_PlayerLevel[id][g_Pl_Race]+1])) {
  for(new 
= (g_PlayerLevel[id][g_Pl_Race]+1); MAX_LEVEL; ++i) {
   if(
g_PlayerXP[id][g_Pl_Race] >= xplevel_lev[i]) {
    
lvled true
    g_PlayerLevel
[id][g_Pl_Race] += i
   
}
  }
 }
 
 
set_player_race(id)
 
 
set_hudmessage(025500.020.701.05.0)
 
show_hudmessage(id"Race: %s^nLevel: %d^nXP: %d"g_PlayerRaceName[id], g_PlayerLevel[id][g_Pl_Race], g_PlayerXP[id][g_Pl_Race])
 
 if(
lvled) {
 
  
set_hudmessage(25500, -1.0, -1.010.56.0)
  
show_hudmessage(id"Congratulations! You gained a level!!!^nYou are now level %d"g_PlayerLevel[id][g_Pl_Race])
 
  if (
file_exists("sound/wishmaster/levelup2.wav")==&& is_user_alive(id)) {
   
emit_sound(id,CHAN_AUTO"wishmaster/levelup2.wav"1.0ATTN_NORM0PITCH_NORM)
  }
 }
 
 return 
PLUGIN_CONTINUE


The clients level is always "0"... It never changes...

BigDontCry 11-16-2007 14:04

Re: Variable (array?) trouble...
 
Here's my "death" function...

PHP Code:

public death() {
 
 new 
killer read_data(1)
 new 
victim read_data(2)
 new 
headshot read_data(3)
 
 new 
g_Pl_Race g_PlayerRace[killer]
 
 new 
kname[32], vname[32]
 
get_user_name(killerkname31)
 
get_user_name(victimvname31)
 
 if(
is_user_connected(killer)) {
 
  
xpgiven xpgiven_lev[g_PlayerLevel[killer][g_Pl_Race]]
  
g_PlayerXP[killer][g_Pl_Race] += xpgiven
 
  client_print
(killerprint_chat"[%s] You recieved %d XP for killing %s"MODxpgivenvname)
 
 }
 
 return 
PLUGIN_CONTINUE


The players XP won't increase...
The client_print shows the right information (lvl 0 get 60 XP for a kill)... But it just won't add that to the clients XP.... :(

[ --<-@ ] Black Rose 11-16-2007 15:15

Re: Variable (array?) trouble...
 
show xplevel_lev

BigDontCry 11-16-2007 15:33

Re: Variable (array?) trouble...
 
PHP Code:

new g_PlayerXP[MAX_PLAYERS][TOTAL_RACES]
new 
g_PlayerLevel[MAX_PLAYERS][TOTAL_RACES]
new 
g_PlayerRace[MAX_PLAYERS]
new 
g_PlayerRaceName[MAX_PLAYERS][18]
 
new 
xplevel_base[11] = {0,150,300,600,1000,1500,2100,2800,3600,4500,5500}
new 
xplevel_lev[MAX_LEVEL] = 0
new xpgiven_lev[MAX_LEVEL] = 0
new xpgiven 

PHP Code:

public set_xp_frontend() {
 
 for(new 
0MAX_LEVELj++) {
  if(
<= 10) {
   
xplevel_lev[j] = xplevel_base[j]
  } else {
   
xplevel_lev[j] = XP_PER_LEVEL_BASE + ((10) * XP_PER_LEVEL)
  }
 
  
xpgiven_lev[j] = XP_BASE + (XP_ADD_LEVEL)
 }



Plugin_init
PHP Code:

public plugin_init() {
 
 
register_plugin("MyMod""1.0""Greven")
 
 
register_event("DeathMsg""death""a")
 
set_task(0.01"set_xp_frontend"456)
 
set_task(0.1"show_player_stats",0,"",0,"b")



BigDontCry 11-16-2007 15:41

Re: Variable (array?) trouble...
 
Oh, darn... I see the problem... set_task in plugin_init, it doesn't forward the id to show_player_stats(id) function....

I want the stats to be on-screen all the time, is there a smoother way than client_PreThink to do this? My experience is that client_PreThink lags the server quite alot...


All times are GMT -4. The time now is 01:12.

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