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

[QUESTION] hud messages using stock written by jopmako


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Rav3n!
Junior Member
Join Date: May 2007
Location: UK
Old 05-07-2007 , 11:33   [QUESTION] hud messages using stock written by jopmako
Reply With Quote #1

hello everyone,

a quick questions from a new guy,

jopmako wrote a hud message stock which looks like this

Code:
// Stock written by jopmako
stock SendMsg_TextMsg(client, type, const String:szMsg[], any:...)
{
   if (strlen(szMsg) > 191){
      LogError("Disallow string len(%d) > 191", strlen(szMsg));
      return;
   }

   decl String:buffer[192];
   VFormat(buffer, sizeof(buffer), szMsg, 4);

   new Handle:hBf;
   if (!client)
      hBf = StartMessageAll("TextMsg");
   else hBf = StartMessageOne("TextMsg", client);

   if (hBf != INVALID_HANDLE)
   {
      BfWriteByte(hBf, type);
      BfWriteString(hBf, buffer);
      EndMessage();
   }
}
and i came across it when looking in sslice's script for a c4 countdown, where in the centre of the screen it counts down the last 5 seconds, and well i was new to scripting and thought i might have a go with printing a message on screen for when a ingame event occurs. the one i used was the common headshot event. but i now have a problem cause when i compile the plugin im running into 3 errors (run using the web compiler)

the code i have used is as follows and was wondering if anyone can point me in the direction of were i have gone wrong many thanks to anyone that can help

Code:
#include <sourcemod>

(then the above code from jopmako)

public OnPluginStart()
{
    HookEvent("headshot", event_headshot, EventHookMode_Pre);
}

public event_headshot(Handle:event, const String:name[], bool:dontBroadcast)
(
    SendMsg_TextMsg(0, TEXTMSG_PRINTCENTER, "Headshot");
    
    return Plugin_Continue
}
Rav3n! is offline
BAILOPAN
Join Date: Jan 2004
Old 05-07-2007 , 12:28   Re: [QUESTION] hud messages using stock written by jopmako
Reply With Quote #2

Show the errors.

EDIT: It looks like the compiler isn't showing errors.. lemme fix that
__________________
egg
BAILOPAN is offline
BAILOPAN
Join Date: Jan 2004
Old 05-07-2007 , 12:39   Re: [QUESTION] hud messages using stock written by jopmako
Reply With Quote #3

Okay, the compiler should show errors now.
__________________
egg
BAILOPAN is offline
jopmako
Senior Member
Join Date: Jul 2006
Location: QQ:331537639
Old 05-07-2007 , 12:41   Re: [QUESTION] hud messages using stock written by jopmako
Reply With Quote #4

there is not "heatshot" event

Quote:
[copy from modevents.res]
"player_death" // a game event, name may be 32 charaters long
{
// this extents the original player_death by a new fields
"userid" "short" // user ID who died
"attacker" "short" // user ID who killed
"weapon" "string" // weapon name killer used
"headshot" "bool" // singals a headshot
}
try this (untest)
Code:
public OnPluginStart()
{
    HookEvent("player_death", event_headshot, EventHookMode_Pre);
}
public event_headshot(Handle:event, const String:name[], bool:dontBroadcast)
(
   if (GetEventBool(event, "headshot"))
      SendMsg_TextMsg(0, TEXTMSG_PRINTCENTER, "Headshot");
    return Plugin_Continue
}
__________________
QQ31537639
jopmako is offline
Send a message via MSN to jopmako
Rav3n!
Junior Member
Join Date: May 2007
Location: UK
Old 05-08-2007 , 07:17   Re: [QUESTION] hud messages using stock written by jopmako
Reply With Quote #5

hello again sorry bout no reply. and thanks for thehelp

i had a look this morning before i came on to see what was up with the code and notice as you stated i hadn't hooked the event player death, and so the event headshot doesn't exist, i then added as you have stated, but then compiled using web cause i cannot work the compiler in the sourcemod sdk compiled and hello errors

so ran jopmako's code above and got the below
Code:
/home/groups/sourcemod/upload_tmp/text5UDLKQ.sp(43 -- 44) : error 029: invalid expression, assumed zero
/home/groups/sourcemod/upload_tmp/text5UDLKQ.sp(45) : error 021: symbol already defined: "SendMsg_TextMsg"
/home/groups/sourcemod/upload_tmp/text5UDLKQ.sp(46) : error 010: invalid function or declaration
i looked and thought hmmmmm stuff

i so new to this its funny, any ideas cause the compiler errors mean nothing cause i dont have a great understanding of the sourcepawn so it would be nice to learn from and maybe ideas and not answers to me problem would be ace

many thanks

the complete code run is below

Code:
#include <sourcemod>

public Plugin:myinfo = 
{
    name = "Plugin",
    author = "People",
    description = "A plugin",
    version = "0.0.0.1",
    url = "www.sourcemod.net"
};


// Stock written by jopmako
stock SendMsg_TextMsg(client, type, const String:szMsg[], any:...)
{
   if (strlen(szMsg) > 191){
      LogError("Disallow string len(%d) > 191", strlen(szMsg));
      return;
   }

   decl String:buffer[192];
   VFormat(buffer, sizeof(buffer), szMsg, 4);

   new Handle:hBf;
   if (!client)
      hBf = StartMessageAll("TextMsg");
   else hBf = StartMessageOne("TextMsg", client);

   if (hBf != INVALID_HANDLE)
   {
      BfWriteByte(hBf, type);
      BfWriteString(hBf, buffer);
      EndMessage();
   }
}


public OnPluginStart()
{
    HookEvent("player_death", event_headshot, EventHookMode_Pre);
}
public event_headshot(Handle:event, const String:name[], bool:dontBroadcast)
(
   if (GetEventBool(event, "headshot"))
      SendMsg_TextMsg(0, TEXTMSG_PRINTCENTER, "Headshot");
    return Plugin_Continue
}
edit: a quick one, the section

Code:
public event_headshot(Handle:event, const String:name[], bool:dontBroadcast)
(
   if (GetEventBool(event, "headshot"))
      SendMsg_TextMsg(0, TEXTMSG_PRINTCENTER, "Headshot");
    return Plugin_Continue
}
is a if then else statement and there is only the if section section of the code, this is due to the headshot event returning a boolen value one or zero, and that the reason for missing the else is due to there being no need for it because if there is no headshot that event hasn't been hooked??

Last edited by Rav3n!; 05-08-2007 at 07:32. Reason: thought about stuff
Rav3n! is offline
jopmako
Senior Member
Join Date: Jul 2006
Location: QQ:331537639
Old 05-09-2007 , 09:22   Re: [QUESTION] hud messages using stock written by jopmako
Reply With Quote #6

Code:
#include <sourcemod>
public Plugin:myinfo = 
{
    name = "Plugin",
    author = "People",
    description = "A plugin",
    version = "0.0.0.1",
    url = "www.sourcemod.net"
};
 
#define HUD_PRINTNOTIFY  1
#define HUD_PRINTCONSOLE 2
#define HUD_PRINTTALK  3
#define HUD_PRINTCENTER  4 
stock SendMsg_TextMsg(client, type, const String:szMsg[], any:...)
{
   if (strlen(szMsg) > 191){
      LogError("Disallow string len(%d) > 191", strlen(szMsg));
      return;
   }
   decl String:buffer[192];
   VFormat(buffer, sizeof(buffer), szMsg, 4);
   new Handle:hBf;
   if (!client)
      hBf = StartMessageAll("TextMsg");
   else hBf = StartMessageOne("TextMsg", client);
   if (hBf != INVALID_HANDLE)
   {
      BfWriteByte(hBf, type);
      BfWriteString(hBf, buffer);
      EndMessage();
   }
}
public OnPluginStart()
{
    HookEvent("player_death", event_headshot);
}
 
public Action:event_headshot(Handle:event, const String:name[], bool:dontBroadcast)
{
   if (GetEventBool(event, "headshot"))
      SendMsg_TextMsg(0, HUD_PRINTCENTER, "Headshot");
   return Plugin_Continue
}
__________________
QQ31537639
jopmako is offline
Send a message via MSN to jopmako
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 16:36.


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