AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   New round events + some other things (https://forums.alliedmods.net/showthread.php?t=61901)

AceDude 10-13-2007 13:01

New round events + some other things
 
Im making my first serious plugin and i have my first serious problem.
Thing that plugin should do is finding user id and using in function called every round to add $. Amount of $ will be diffrent for every user.


PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
client_putinserver(id)
{
    new 
player_id id
//How to add parameter here?
    
register_logevent("round_start()"2"1=Round_Start")
}


public 
round_start(player_id) {
    
client_print(player_idprint_chat"[AMXX] NOWA RUNDA---------------------<<<")
    
cs_set_user_money(player_idcs_get_user_money(player_id) + 6666)
    
client_print(player_idprint_chat"[AMXX] CSN-SQL: Dodano 6666$")



Arkshine 10-13-2007 13:14

Re: New round events + some other things
 
It's a global event so you have to use get_players() + for().

Also event has to be registered in plugin_init().

Code:
    #include <amxmodx>     #include <cstrike>     public plugin_init()     {         register_plugin( "Plugin", "1.0", "Amxx Community" );                 register_logevent( "eRound_start", 2, "1=Round_Start" );     }         public eRound_start()     {         new iPlayers[32], iNum, iPid;         get_players( iPlayers, iNum, "a" );                 for( new i; i < iNum; i++ )         {             iPid = iPlayers[i];                         client_print( iPid, print_chat, "[AMXX] NOWA RUNDA---------------------<<<" );             cs_set_user_money( iPid, cs_get_user_money( iPid + 6666 ) );             client_print( iPid, print_chat, "[AMXX] CSN-SQL: Dodano 6666$" );         }         }

AceDude 10-13-2007 13:25

Re: New round events + some other things
 
If im not stupid, this will work same for every player?
Values will be readen from SQL, sometimes it will be 0...

ConnorMcLeod 10-13-2007 13:51

Re: New round events + some other things
 
You could set the money at ResetHUD event, so players can buy before the event roundstart.

Read this -tut- for more informations.

AceDude 10-13-2007 15:05

Re: New round events + some other things
 
Thx for link.

So, i have modified my own code, and it works.. But, hm, i thought that it will work all the time for each other player, and i see that playa_id is still 6 (i have 6 players on the server)... so is whole idea dead? rawr... help me please!

PHP Code:

new playa_id;


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_logevent("round_start"2"1=Round_Start");
}

public 
client_putinserver(id) {
    
playa_id id;
    return 
playa_id;
}

public 
round_start() {
    
// 1 is my real ID, im the first player
    
client_print(1print_chat"[AMXX] NEW ROUND| Your ID is %d"playa_id);


EDIT
Problem sloved using spawn detection.

ConnorMcLeod 10-13-2007 15:32

Re: New round events + some other things
 
With your code, player_id is always the id of the last player connected to your server (even if this player has left).
Also, return player_id is non sense in client_putinserver function.

Either you use round_start event, and then take Arkshine's code that execute command through all alive players, either you use ResetHUD event.

Look at this code, i hope you will understand

Code:
#include <amxmodx> #define MAX_PLAYERS 32 new bool:g_RestartAttempt[MAX_PLAYERS+1] public plugin_init() {     register_plugin("Base Plugin","0.1","AceDude")         register_event("HLTV", "eNewRound", "a", "1=0", "2=0")     register_logevent("eRoundStart", 2, "1=Round_Start")     register_logevent("eRoundEnd", 2, "1=Round_End")         register_event("TextMsg", "eRestartAttempt", "a", "2=#Game_will_restart_in")     register_event("ResetHUD", "eResetHUD", "be")     register_clcmd("clcmd_fullupdate", "fullupdateCmd") } public fullupdateCmd() {     return PLUGIN_HANDLED_MAIN } public eRestartAttempt() {     new players[32], num     get_players(players, num, "a")     for (new i; i < num; ++i)         g_RestartAttempt[players[i]] = true } public eResetHUD(id) {     if (g_RestartAttempt[id]) {         g_RestartAttempt[id] = false         return     }     event_player_spawn(id) }   public event_player_spawn(id) {     // put here the code you want to execute to player, each time he is spawning     client_print(id, print_chat, "[AMXX] Player Spawn | Your ID is %d", id) } public eNewRound() {     new players[32], inum, player     get_players(players, inum) // i didn't put flag "a" here because dead players haven't spawn yet     for(new i; i<inum; i++)     {         player = players[i]         client_print(player, print_chat, "[AMXX] Freezetime | Your ID is %d", player)     } } public eRoundStart() {     new players[32], inum, player     get_players(players, inum, "a")     for(new i; i<inum; i++)     {         player = players[i]         client_print(player, print_chat, "[AMXX] Round Start | Your ID is %d", player)     } } public eRoundEnd() {     new players[32], inum, player     get_players(players, inum, "a")     for(new i; i<inum; i++)     {         player = players[i]         client_print(player, print_chat, "[AMXX] Round End | Your ID is %d", player)     } }

Arkshine 10-13-2007 15:43

Re: New round events + some other things
 
You don't understand.

'Round start' event is a global event. It happens after the freeze time.

You have to retrieve the players list using get_players(). See my snippet above.

But if you want to set money before the players start to buy weapons, you have to use 'new round' or 'reset hud' event.

Code:
    #include <amxmodx>     #include <cstrike>     public plugin_init()     {         register_plugin( "Plugin", "1.0", "Amxx Community" );                 register_event( "HLTV", "eNew_round", "a", "1=0", "2=0" );     }         public eNew_round()     {         new iPlayers[32], iNum, iPid;         get_players( iPlayers, iNum, "a" );                 for( new i; i < iNum; i++ )         {             iPid = iPlayers[i];                         client_print( iPid, print_chat, "[AMXX] NOWA RUNDA---------------------<<<" );             cs_set_user_money( iPid, cs_get_user_money( iPid + 6666 ) );             client_print( iPid, print_chat, "[AMXX] CSN-SQL: Dodano 6666$" );         }     }

New Round is happen at the Freeze Time start.

EDIT: @connor : Damn you. ;)

AceDude 10-13-2007 16:39

Re: New round events + some other things
 
connor: "i hope you will understand"
arkshine "You don't understand."

lol ;)

Thanks for your support. I'm using VEN's code (http://forums.alliedmods.net/showthread.php?t=42159). I will (propably) have some more problems tommorow, cause it's only begginning of much bigger plugin.

Listing of plugin (feel free to comment):
PHP Code:

#define MAX_PLAYERS 32
new bool:g_restart_attempt[MAX_PLAYERS 1]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_event("ResetHUD""event_hud_reset""be")
    
register_clcmd("fullupdate""clcmd_fullupdate"
    
register_event("TextMsg""event_restart_attempt""a""2=#Game_will_restart_in")
}

public 
clcmd_fullupdate() {
    return 
PLUGIN_HANDLED_MAIN
}
 
public 
event_restart_attempt() {
    new 
players[32], num
    get_players
(playersnum"a")
    for (new 
inum; ++i)
        
g_restart_attempt[players[i]] = true
}
 
public 
event_hud_reset(id) {
    if (
g_restart_attempt[id]) {
        
g_restart_attempt[id] = false
        
return
    }
    
event_player_spawn(id)
}
 
// this function is called on player spawn
public event_player_spawn(id) {
    
client_print(idprint_chat"[AMXX] SPAWN: NOWA RUNDA | Twoje ID to %d"id);




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

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