AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Why dun this work? (https://forums.alliedmods.net/showthread.php?t=14107)

v3x 06-10-2005 00:44

Why dun this work?
 
(it's very rare that I ask for help in here :p)
Code:
#include <amxmodx> public plugin_init()     register_plugin("HUD Score","0.1","v3x") #define TASK_ID 2934 public client_connect(id) set_task(1.0,"show_message",TASK_ID+id) public client_disconnect(id) remove_task(TASK_ID+id) public show_message(id) {     new frags = get_user_frags(id)     new deaths = get_user_deaths(id)     new msgstr[64]     format(msgstr,63,"Kills: %i / Deaths: %i",frags,deaths)     set_hudmessage(255,255,255,-1.0,0.35,2,0.1,1.0,0.02,0.02,10)     show_hudmessage(id,msgstr)     return PLUGIN_HANDLED }

It's so simple.. :p

Maybe I just have the coords off of the screen, haha.

WaZZeR++ 06-10-2005 07:35

dont you need to creat a loop that display it, the scor isupdating al the time.

can there be anything wrong with:
Code:
set_hudmessage(255,255,255,-1.0,0.35,2,0.1,1.0,0.02,0.02,10)
but I dont, everything look, cant find the problem ether...

xeroblood 06-10-2005 13:20

Re: Why dun this work?
 
As far as I know, the ID being passed to your "show_message" function will be the same as the Task ID, which you put as: TASK_ID+id, but then you try to use that ID in the show_message function as if it were a player ID.. I think you should minus TASK_ID from the player ID first..

Code:
#include <amxmodx> public plugin_init()     register_plugin("HUD Score","0.1","v3x") #define TASK_ID 2934 public client_connect(id) set_task(1.0,"show_message",TASK_ID+id) public client_disconnect(id) remove_task(TASK_ID+id) public show_message(id) {     new playerID = id - TASK_ID     new frags = get_user_frags(playerID)     new deaths = get_user_deaths(playerID)     new msgstr[64]     format(msgstr,63,"Kills: %i / Deaths: %i",frags,deaths)     set_hudmessage(255,255,255,-1.0,0.35,2,0.1,1.0,0.02,0.02,10)     show_hudmessage(playerID,msgstr)     return PLUGIN_HANDLED }

I hope that helps, or even works!

v3x 06-10-2005 16:34

Still dun work.. :\

I tried to make it show in the StatusText thinger, but I got an error and teh server went boom.

Code:
#include <amxmodx> public plugin_init()     register_plugin("HUD Score","0.1","v3x") #define TASK_ID 2934 public client_connect(id) set_task(3.0,"show_message",TASK_ID+id) public client_disconnect(id) remove_task(TASK_ID+id) public show_message(id) {     new playerID = id - TASK_ID     new frags = get_user_frags(playerID)     new deaths = get_user_deaths(playerID)     new msgstr[64]     format(msgstr,63,"Kills: %i / Deaths: %i",frags,deaths)     message_begin(MSG_ONE,get_user_msgid("StatusText"),{0,0,0},id)     write_byte(0)     write_string(msgstr)     message_end()     return PLUGIN_HANDLED }

Quote:

FATAL ERROR (shutting down): MSG_ONE or MSG_ONE_UNRELIABLE with no target entity
---
HUD CODE (changed a couple things):
Code:
#include <amxmodx> public plugin_init()     register_plugin("HUD Score","0.1","v3x") #define TASK_ID 2934 public client_putinserver(id) set_task(1.0,"show_message",TASK_ID+id,_,_,"b") public client_disconnect(id) remove_task(TASK_ID+id) public show_message(id) {     new playerID = id - TASK_ID     new frags = get_user_frags(playerID)     new deaths = get_user_deaths(playerID)     new msgstr[64]     format(msgstr,63,"Kills: %i / Deaths: %i",frags,deaths)     set_hudmessage(255,255,255,-1.0,0.35,2,0.1,1.0,0.02,0.02,10)     show_hudmessage(playerID,msgstr)     return PLUGIN_HANDLED }

v3x 06-11-2005 10:52

Bah, I got it workin..

xeroblood 06-11-2005 16:49

I know this is kinda off-topic, but you should always use MSG_ONE_UNRELIABLE instead of MSG_ONE.

By using MSG_ONE you are telling the HL Engine that the message is to be put into the reliable stream for sending and if for some reason the message can't be sent then the HL Engine produces a Fatal Error and your server crashes..

If you use MSG_ONE_UNRELIABLE you are telling the HL Engine to send the message unreliably, meaning that if the message can't be sent it is okay.. This way the server continues on and doesn't crash..

Either way, using MSG_ONE_UNRELIABLE or MSG_ONE will still cause the message to be sent, and in both cases the message may fail, the notable difference is what to do if it does fail (crash or continue)..

Overall, use MSG_ONE if you want the server to crash if the message can't be sent, or use MSG_ONE_UNRELIABLE if you don't want it to crash.. :D

xeroblood 06-11-2005 16:53

Oh, i noticed why it crashed on you too, you put 'id' in the message_begin function, when you shoulda put 'playerID'...

Quote:

Originally Posted by v3x
Code:
#include <amxmodx> // [...] public show_message(id) {     new playerID = id - TASK_ID     // [...]     message_begin(MSG_ONE,get_user_msgid("StatusText"),{0,0,0},id)     write_byte(0)     write_string(msgstr)     message_end()     return PLUGIN_HANDLED }

^^^ Notice it?


All times are GMT -4. The time now is 16:47.

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