AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with file-read (https://forums.alliedmods.net/showthread.php?t=64001)

Grinf4ce 12-05-2007 15:27

Help with file-read
 
Hello there,
i'm a new little coder and want to recode a plugin.
Its this: Hats

I tried to give every player a hat when he spawn first time on map.

Originalfunction of Hats:
PHP Code:

public Give_Hat(id)
{
    new 
smodelnum[5], name[32]
    
read_argv(1,name,31)
    
read_argv(2,smodelnum,4)
    
    new 
player cmd_target(id,name,2)
    if (!
player) {
        
client_print(id,print_chat,"[%s] Player With That Name Does Not Exist.",PLUG_TAG)
        return 
PLUGIN_HANDLED
    
}
    
    new 
imodelnum = (str_to_num(smodelnum))
    if (
imodelnum MAX_HATS) return PLUGIN_HANDLED
    
    Set_Hat
(player,imodelnum,id)

    return 
PLUGIN_CONTINUE


But i only get the error "[HATS] Player With That Name Does not Exist" when i join the server and spawn the first time.
How i had to modify the command, which i send to client @ first spawn?
PHP Code:

 new nick[33]
 new 
model[2]
 
 
get_user_name (id,nick,32)
 
model "1"// Automatic Modelnr 1
 
 
client_cmd(id,"amx_givehat #%n %m",id,model

Can someone help a little Codingnoob? :-/
Please.

Greets, Grinf4ce

Emp` 12-05-2007 18:29

Re: Help: A question to a clientcommand
 
Code:

client_cmd(id,"amx_givehat %s %s",nick,model)

YamiKaitou 12-05-2007 18:55

Re: Help: A question to a clientcommand
 
PHP Code:

client_cmd(id,"amx_givehat #%d %s",get_user_userid(id),model


This will work better, as if you use id, you probably won't get the right person or a person at all

Grinf4ce 12-06-2007 01:07

Re: Help: A question to a clientcommand
 
Thank you YamiKoitou!
Works :-D

But Now the Bots havent a hat, when they join the server. :-/
Is the get_user_userid(id) only for humanplayer or havent bots the "first spawn" event?

YamiKaitou 12-06-2007 01:19

Re: Help: A question to a clientcommand
 
If the bots are not getting a hat, I would look at the hats plugin. It may be blocking it if it is trying to give one to a bot

purple_pixie 12-06-2007 04:16

Re: Help: A question to a clientcommand
 
If you are hooking ResetHUD then no, bots don't have a spawn event.

Use register_forward(FM_Spawn,...) (FakeMeta)
or RegisterHam(Ham_Spawn,"player",...) (HamSandwich)

Emp` 12-07-2007 00:30

Re: Help: A question to a clientcommand
 
Quote:

Originally Posted by purple_pixie (Post 560386)
If you are hooking ResetHUD then no, bots don't have a spawn event.

yes they do.

purple_pixie 12-07-2007 04:28

Re: Help: A question to a clientcommand
 
Well I just played around with this:

Code:
#include <amxmodx> #include <amxmisc> #include <famekmeta> stock pixie_createbot() {     return pixie_createnamedbot("player_npc") } // creates a bot called <name> // returns player id stock pixie_createnamedbot(name[]) {     new bot=engfunc(EngFunc_CreateFakeClient,name)     new arr[128]     dllfunc(DLLFunc_ClientConnect, bot,name,"127.0.0.1",arr)     dllfunc(DLLFunc_ClientPutInServer, bot)     set_pev(bot,pev_spawnflags, pev(bot,pev_spawnflags) | FL_FAKECLIENT)     set_pev(bot,pev_flags, pev(bot,pev_flags) | FL_FAKECLIENT)     cs_set_user_team(bot,CS_TEAM_CT,CS_CT_GSG9 )     spawn(bot)     spawn(bot)     spawn(bot)     return bot } public plugin_init() {     register_plugin("Reset that Hud to them", "1.0", "Pixie")     register_event("ResetHUD","on_hudreset","b") ;     register_event("ResetHUD","on_globalhudreset","c") ;     register_srvcmd("pixie","pixie") ; } public on_hudreset() {     log_amx("Omg! Some noob reset my HUD!") ; } public on_globalhudreset() {     log_amx("Omg! Some noob reset all our HUD's!") ; } new players[32] ; new playercount ; public pixie() {     players[playercount++] = pixie_createbot()     for ( new i ; i < playercount ; i ++ )     {         spawn(players[i]) ;     } }

And it only logged anything when I called sv_restartound
(When I called it, not when the round restarted - call sv_restartround 10 and it's obvious when it occurs)

Grinf4ce 12-07-2007 12:58

Re: Help: A question to a clientcommand
 
Okay now it works.

But i have again a little noob question.
I wrote an addon which write the steamid in a file.

Now i want to read it out, and search for the steamid, which you use.
If the script found your id, you cant pick up the gift, else you can pickup the gift.

PHP Code:

    new readdata[128],steamid[32],txtlen;
    new 
parsedsteamid[32];
    
    
get_user_authid(id,steamid,31);
    
    new 
fsize file_size(filename,1);
    new 
status[2];

    for (new 
line=0;line<=fsize;line++)
    {
        
read_file(filename,line,readdata,127,txtlen); // Datei auslesen
        
parse(readdata,parsedsteamid,31); // Parsen
        
        
if(equal(steamid,parsedsteamid)) // Überprüfen ob Daten gleich sind..
        
{
            
client_print(id,print_chat,"* Sorry, but you cant pickup this gift!.");
            
status "1";
            break;
        }
        else
        {
            
status "0";
        }
    }
    
    if(
status "0")
    {
        
client_cmd(id,"amx_register");
        
remove_entity(pTouched);
    } 

But it doesnt work, you can pickup the gift again and again, and it wrote again and again in the file :-/

Oh man my bad english, i hope someone understand what i mean *g*


All times are GMT -4. The time now is 11:09.

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