AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Some Shi* - Again (https://forums.alliedmods.net/showthread.php?t=56334)

shine771 06-11-2007 17:33

Some Shi* - Again
 
Sorry that i'm bothering you every day =/

But i need to finish this plugin

Here's The Code:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "Frag Limit"
#define VERSION "1.0"
#define AUTHOR "Sh!nE*"

#define MAX_PLAYERS 32

new bool:g_restart_attempt[MAX_PLAYERS 1]
new 
fraglimit_onfraglimit

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
fraglimit_on register_cvar("fl_on","1")
    
fraglimit register_cvar("fl_fraglimit","50")
    
    
register_event("ResetHUD""event_hud_reset""be")
    
register_clcmd("fullupdate""clcmd_fullupdate"
    
register_event("TextMsg""event_restart_attempt""a""2=#Game_will_restart_in")
    
set_task(1.0,"set_timeleft_back")    
}

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)
}

public 
event_player_spawn(id)
{    
    if(!
get_pcvar_num(fraglimit_on))
    return 
PLUGIN_HANDLED
    
    
new Frags get_user_frags(id)
    
    new 
players[32], num
    get_players
(playersnum)
    new 
i
    
for (i=0i<numi++)
    {
        if(
Frags get_pcvar_num(fraglimit))
        {
            
set_user_frags(idFrags)
            
set_hudmessage(25500, -1.00.1806.05.0)
            
show_hudmessage(players[i], "%s Won the match!!!"id)
            
set_task(5.0,"set_timelimit")
        }    
    }
    
ShowFragsLeft(id)
    return 
PLUGIN_CONTINUE
}
public 
set_timelimit()
{
    
set_cvar_num("mp_timelimit"1)
    
set_hudmessage(25500, -1.00.2006.05.0)
    
show_hudmessage(0"Map change after 1 minute")
}

public 
ShowFragsLeft(id)
{
    new 
Frags get_user_frags(id)
    new 
Frags_left get_pcvar_num(fraglimit) - Frags
    
    set_hudmessage
(25500, -1.00.9006.05.0)
    
show_hudmessage(id"%d Frags Remaining"Frags_left)
    
    
set_task(1.0,"ShowFragsLeft")
}

public 
set_timeleft_back()
{
    new 
timeleft get_cvar_num("mp_timelimit")
    
    
set_cvar_num("mp_timelimit"timeleft)


Maybe im just stupid :D
It doesn't give me any errors... Just doesn't work... It just show's me:

10 Frags Remaining < all the time - it doesn't change when i kill someone.
And when someone gets 10 Frags - It doesn't show the message.
And it doesn't change the timelimit back... Every next map has 1min timelimit < LOL
I know the timelimit thing isn't a good method... But i don't know other way that i can do this...
I just wan't to make this plugin... It remind's me "quake 3 arena"

Thanks.

If i wrote some words incorrectly - Sorry for my english

Vet 06-12-2007 00:51

Re: Some Shi* - Again
 
What Mod are you trying to use this on?
If its DoD, you need to use the dodfun include. To do that, change:

#include <fun>
to
#include <dodfun>

set_user_frags(id, Frags)
to
dod_set_user_kills(id, Frags, 1)

new Frags = get_user_frags(id)
to
new Frags = dod_get_user_kills(id)

If its not DoD, sorry, can't help.
ps, your English is great. I commend you for learning it so well.

pRED* 06-12-2007 02:58

Re: Some Shi* - Again
 
Lol theres quite a few things wrong.

Firstly reset_back wont ever do anything. Your checking a cvar and then setting it to itself. Pointless?

Checking for a winner or player spawn (resetHUD) doesn't seem like the best way. I'm working on something similar at the moment and I reckon deathmsg would be the best (the amount of frags changes when someone dies so this is the best time to check)

To set 1 minute remaining you can set mp_timelimit to 1. You need to the value of halflife time and add 1 to it and set mp_timelimit to that

Code:
new Float:time=halflife_time() + 60.0 set_cvar_num("mp_timelimit",floatround(time/60))

Theres some otherthing like set_user_frags(id).. inside a get player for loop.
I don't understand what this is supposed to do but it should at least be players[i]..

Have a play around with that and see how far you get. I can show you how I did it if you really get stuck.
Good Luck

shine771 06-12-2007 07:15

Re: Some Shi* - Again
 
Thanks.

This mod is for CS(Counter-Strike) :O

The "set_user_frags" was ment to "if user gets more frags than 50 it set's their frags to 50. But it doesn't matter anymore.
I'm totally STUCK.
I'd understand just a part of it, can you be more clearer, please.
It shows me "Error: Undefined symbol "halflife_time" on line 68" do i need to create it??? And i didn't understand the DeathMSG event - what to write in it?
i know just the start. I looked at some code's, every DeathMSG event differs from each other, i searched this Forum, Google but i still can't find anything. Can you give me some code for hint?

Here's my code:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "Frag Limit"
#define VERSION "1.0"
#define AUTHOR "Sh!nE*"

#define MAX_PLAYERS 32

new bool:g_restart_attempt[MAX_PLAYERS 1]
new 
fraglimit_onfraglimit

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
fraglimit_on register_cvar("fl_on","1")
    
fraglimit register_cvar("fl_fraglimit","50")
    
    
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)
}

public 
event_player_spawn(id)
{    
    if(!
get_pcvar_num(fraglimit_on))
    return 
PLUGIN_HANDLED
    
    
new Frags get_user_frags(id)
    
    new 
players[32], num
    get_players
(playersnum)
    new 
i
    
for (i=0i<numi++)
    {
        if(
Frags get_pcvar_num(fraglimit))
        {
            
set_user_frags(players[i], Frags)
            
set_hudmessage(25500, -1.00.1806.05.0)
            
show_hudmessage(players[i], "%s Won the match!!!"id)
            
set_task(5.0,"set_timelimit")
        }    
    }
    
ShowFragsLeft(id)
    return 
PLUGIN_CONTINUE
}
public 
set_timelimit()
{
    new 
Float:time=halflife_time() + 60.0 set_cvar_num("mp_timelimit",floatround(time/60))
    new 
timeleft get_cvar_num("mp_timelimit")
    
set_hudmessage(25500, -1.00.2006.05.0)
    
show_hudmessage(0"Map change after 1 minute")
}

public 
ShowFragsLeft(id)
{
    new 
Frags get_user_frags(id)
    new 
Frags_left get_pcvar_num(fraglimit) - Frags
    
    set_hudmessage
(25500, -1.00.9006.05.0)
    
show_hudmessage(id"%d Frags Remaining"Frags_left)
    
    
set_task(1.0,"ShowFragsLeft")


Thanks again

Vet 06-12-2007 13:46

Re: Some Shi* - Again
 
halflife_time is in the engine module. So you'd need to include it.

You may want to look into using fakemeta.
new Frags = pev(id, pev_frags)
set_pev(id, pev_frags, Frags)

shine771 06-12-2007 16:52

Re: Some Shi* - Again
 
Thanks VET.

I know all of you think: "This guy comes and asks every time he has some difficulties, he so stupid"
It's not like that. I'm trying - this time i was trying to figure out this mess out 1,5h with no break!!!i Just can't
Now my problems are.
10 Frags Remaining < all the time - it doesn't change when i kill someone.
And when someone gets 10 Frags - It doesn't show the message.
TimeLimit thing doesn't work at ALL
I just can't make this plugin, it's so simple. Im just a n00b.
Where should i put the
Code:

new Frags = pev(id, pev_frags)
set_pev(id, pev_frags, Frags)

Here's the CODE... brrr:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>

#define PLUGIN "Frag Limit"
#define VERSION "1.0"
#define AUTHOR "Sh!nE*"

#define MAX_PLAYERS 32

new bool:g_restart_attempt[MAX_PLAYERS 1]
new 
fraglimit_onfraglimit
new timeleft

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
fraglimit_on register_cvar("fl_on","1")
    
fraglimit register_cvar("fl_fraglimit","50")
    
timeleft get_cvar_num("mp_timelimit")
    
    
register_event("DeathMsg","death_a","a")
    
    
set_task(1.0,"set_timelimit_back")
    
    
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)
}

public 
event_player_spawn(id)
{
    
ShowFragsLeft(id)
}
public 
death_a(id)
{    
    if(!
get_pcvar_num(fraglimit_on))
        return 
PLUGIN_HANDLED
    
    
new Frags get_user_frags(id)
    
    new 
players[32], num
    get_players
(playersnum)
    new 
i
    
for (i=0i<numi++)
    {
        if(
Frags get_pcvar_num(fraglimit))
        {
            
set_user_frags(players[i], Frags)
            
set_hudmessage(25500, -1.00.1806.05.0)
            
show_hudmessage(players[i], "%s Won the match!!!"id)
            
set_task(5.0,"set_timelimit")
        }    
    }
    return 
PLUGIN_CONTINUE
}
public 
set_timelimit()
{
    new 
Float:time=halflife_time() + 60.0 set_cvar_num("mp_timelimit",floatround(time/60))
    
set_hudmessage(25500, -1.00.2006.05.0)
    
show_hudmessage(0"Map change after 1 minute")
}

public 
ShowFragsLeft(id)
{    
    new 
Frags get_user_frags(id)
    new 
Frags_left get_pcvar_num(fraglimit) - Frags
    
    set_hudmessage
(25500, -1.00.9006.05.0)
    
show_hudmessage(id"%d Frags Remaining"Frags_left)
    
    
set_task(1.0,"ShowFragsLeft")
}

public 
set_timelimit_back()
{
    
set_cvar_num("mp_timelimit"timeleft)


Thanks. :(

pRED* 06-12-2007 17:17

Re: Some Shi* - Again
 
You're making progress. The reason for your problems is most of the time it doesn't know what 'id' is.

You set the task
Code:
<font color="#000000"><font color="#0000BB">set_task</font><font color="#007700">(</font><font color="#0000BB">1.0</font><font color="#007700">,</font><font color="#DD0000">"ShowFragsLeft"</font><font color="#007700">)</font></font>
and then in the ShoqFragsLeft you have id at the top. The compiler has no way of knowing what id is...

You'd need to change it to
Code:
<font color="#000000"><font color="#0000BB">set_task</font><font color="#007700">(</font><font color="#0000BB">1.0</font><font color="#007700">,</font><font color="#DD0000">"ShowFragsLeft"</font><font color="#007700">,id)</font></font>
, so the code passes the current id number along to the next time it calls it, so it knows which player to display for.

Also your death_a does not have an id parameter. It should be
Code:
public death_a()

Look where you registered the DeathMsg event. It has the flag "a", this means that it is sent to all players at once not a single player, so doesn't come with a specific id number. (messages with the flag b are sent individually (like ResetHUD) so they have an id parameter)

Instead to get the id number of the killer you need to the line

Code:
new killer = read_data(2)
and if you want the victim you need
Code:
new victim = read_data(1)

Link to list of events where you can find what number refers to what

You'll also need to move your get_user_frags statement inside the loop but before the if statement.

This way the loop goes through all the players on the server. First it checks their frags (don't forget players[i]) then it compares if the frags are greater or equal to the limit (make it >= instead of >) and if they are send a message saying they won.

Other things you might want to add are..
Once you find a winner (in the loop) add the command [smallbreak[/small]
So add a line at the end of the if Frags >... put the break command in. This stops the for loop at that point (whats the point in checking for a winner after you've found one?)

A variable to detect a winner has been found. At the top of the code add a variable like..
Code:
new bool:winnerfound=false

Then before the for loop make an if statement like..
Code:
if (winnerfound)      return;

This will quit out of the function and skip the winner check, if a winner has already been found.

Then inside your for loop just before the 'break' command ( a winner has been found) add the line
Code:
winnerfound=true

And that should pretty much do it..

pRED* 06-12-2007 17:19

Re: Some Shi* - Again
 
Double post cause i don't want to edit the previous one because of the code editing bug.

The first two code sections (about set task should be..)

Code:
set_task(1.0,"ShowFragsLeft")

and

Code:
set_task(1.0,"ShowFragsLeft",id)

shine771 06-12-2007 17:47

Re: Some Shi* - Again
 
Big thanks!!!
Just 2 Problems - Sorry that i am disturbing you.

These doesn't show up:
Code:

            set_hudmessage(255, 0, 0, -1.0, 0.18, 0, 6.0, 5.0)
            show_hudmessage(players[i], "%s Won the match!!!", killer)
            set_hudmessage(0, 255, 0, -1.0, 0.39, 0, 6.0, 12.0)
            show_hudmessage(players[i], "And the last frag was %s", victim)

and this:
Code:

    set_hudmessage(255, 0, 0, -1.0, 0.20, 0, 6.0, 5.0)
    show_hudmessage(0, "Map change after 1 minute")

And the biggest one: the map doesn't change

Here's the CODE - again:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>

#define PLUGIN "Frag Limit"
#define VERSION "1.0"
#define AUTHOR "Sh!nE*"

#define MAX_PLAYERS 32

new bool:g_restart_attempt[MAX_PLAYERS 1]
new 
fraglimit_onfraglimit
new timeleft
new bool:winnerfound=false

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
fraglimit_on register_cvar("fl_on","1")
    
fraglimit register_cvar("fl_fraglimit","50")
    
timeleft get_cvar_num("mp_timelimit")
    
    
register_event("DeathMsg","death_a","b")
    
    
set_task(1.0,"set_timelimit_back")
    
    
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)
}

public 
event_player_spawn(id)
{
    
ShowFragsLeft(id)
}
public 
death_a()
{    
    if(!
get_pcvar_num(fraglimit_on))
        return 
PLUGIN_HANDLED
    
    
if (winnerfound)
    return 
PLUGIN_CONTINUE
    
    
new players[32], num
    
new victim read_data(1)
    new 
killer read_data(2)
    
get_players(playersnum)
    new 
i
    
new Frags get_user_frags(players[i])
    
set_user_frags(players[i], Frags)
    for (
i=0i<numi++)
    {
        if(
Frags >= get_pcvar_num(fraglimit))
        {
            
set_hudmessage(25500, -1.00.1806.05.0)
            
show_hudmessage(players[i], "%s Won the match!!!"killer)
            
set_hudmessage(02550, -1.00.3906.012.0)
            
show_hudmessage(players[i], "And the last frag was %s"victim)
            
            
winnerfound=true
            set_task
(5.0,"set_timelimit")
        }    
    }
    return 
PLUGIN_CONTINUE
}
public 
set_timelimit()
{
    new 
Float:time=halflife_time() + 60.0 set_cvar_num("mp_timelimit",floatround(time/60))
    
set_hudmessage(25500, -1.00.2006.05.0)
    
show_hudmessage(0"Map change after 1 minute")
}

public 
ShowFragsLeft(id)
{    
    new 
Frags get_user_frags(id)
    new 
Frags_left get_pcvar_num(fraglimit) - Frags
    
    set_hudmessage
(25500, -1.00.9006.05.0)
    
show_hudmessage(id"%d Frags Remaining"Frags_left)
    
    
set_task(1.0,"ShowFragsLeft"id)
}

public 
set_timelimit_back()
{
    
set_cvar_num("mp_timelimit"timeleft)


Thanks again.

pRED* 06-12-2007 17:58

Re: Some Shi* - Again
 
Try this

Code:
#include <amxmodx> #include <amxmisc> #include <fun> #include <engine> #define PLUGIN "Frag Limit" #define VERSION "1.0" #define AUTHOR "Sh!nE*" #define MAX_PLAYERS 32 new bool:g_restart_attempt[MAX_PLAYERS + 1] new fraglimit_on, fraglimit new timeleft new bool:winnerfound=false public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     fraglimit_on = register_cvar("fl_on","1")     fraglimit = register_cvar("fl_fraglimit","50")         register_event("DeathMsg","death_a","a")           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(players, num, "a")     for (new i; i < num; ++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) } public event_player_spawn(id) {     ShowFragsLeft(id) } public death_a() {         if(!get_pcvar_num(fraglimit_on) || winnerfound)         return PLUGIN_HANDLED             new players[32], num     get_players(players, num)     new Frags     new killer=read_data(1)     new victim=read_data(2)     for (new i=0; i<num; i++)     {     Frags = get_user_frags(players[i])         if(Frags >= get_pcvar_num(fraglimit))         {             set_hudmessage(255, 0, 0, -1.0, 0.18, 0, 6.0, 5.0)             show_hudmessage(0, "%s Won the match!!!", killer)             set_hudmessage(0, 255, 0, -1.0, 0.39, 0, 6.0, 12.0)             show_hudmessage(0, "And the last frag was %s", victim)                         winnerfound=true             set_task(5.0,"set_timelimit")         break         }         }     return PLUGIN_CONTINUE } public set_timelimit() {     new Float:time=halflife_time() + 60.0 ; set_cvar_num("mp_timelimit",floatround(time/60))     set_hudmessage(255, 0, 0, -1.0, 0.20, 0, 6.0, 5.0)     show_hudmessage(0, "Map change after 1 minute") } public ShowFragsLeft(id) {         new Frags = get_user_frags(id)     new Frags_left = get_pcvar_num(fraglimit) - Frags         set_hudmessage(255, 0, 0, -1.0, 0.90, 0, 6.0, 5.0)     show_hudmessage(id, "%d Frags Remaining", Frags_left)         set_task(1.0,"ShowFragsLeft", id) }


All times are GMT -4. The time now is 10:29.

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