Raised This Month: $32 Target: $400
 8% 

Worldspawn Keyvalue Access


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ts2do
Senior Member
Join Date: Mar 2004
Old 07-28-2007 , 15:10   Worldspawn Keyvalue Access
Reply With Quote #1

Here's a function that retrieves a keyvalue from the worldspawn entity in the current map.
Code:
#include <amxmodx> #include <regex> #define CACHE_WORLDSPAWN_DATA public bool:get_worldspawn_keyvalue(szKeyName[], szRet[], iLen) { #if defined CACHE_WORLDSPAWN_DATA     static bGotWorldData = false, szWorldData[1024];     if(!bGotWorldData)     { #else     new szWorldData[1024]; #endif         new szFileName[128], szMapName[64];         get_mapname(szMapName, 63);         formatex(szFileName, 127, "maps/%s.bsp", szMapName);         new hFile = fopen(szFileName, "rb");         if (hFile)         {             new iOffset, chNewChar, n;             fseek(hFile, 4, SEEK_SET);             fread(hFile, iOffset, BLOCK_INT);             fseek(hFile, iOffset, SEEK_SET);             do             {                 fread(hFile, chNewChar, BLOCK_CHAR)                 szWorldData[n++]  = chNewChar;             }while(n<1024&&chNewChar!='}')             fclose(hFile);             new szBuf[32], iNum, szError[128];             formatex(szBuf, 31, "^"%s^"(.+)^"(.+)^"", szKeyName);             new Regex:hReg = regex_match(szWorldData, szBuf, iNum, szError, 127);             if(hReg>=REGEX_OK)             {                 regex_substr(hReg, 2, szRet, iLen-1);                 regex_free(hReg);                 return true;             }         } #if defined CACHE_WORLDSPAWN_DATA     } #endif     return false; }
__________________

Last edited by ts2do; 07-31-2007 at 05:10.
ts2do is offline
Send a message via AIM to ts2do
Zenith77
Veteran Member
Join Date: Aug 2005
Old 08-01-2007 , 14:07   Re: Worldspawn Keyvalue Access
Reply With Quote #2

All I can say is, nice.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
ts2do
Senior Member
Join Date: Mar 2004
Old 08-01-2007 , 20:20   Re: Worldspawn Keyvalue Access
Reply With Quote #3

Note that this method doesn't work well if a keyvalue contains the character } in it.
__________________
ts2do is offline
Send a message via AIM to ts2do
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 23:47.


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