AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   What's wrong with my code? (https://forums.alliedmods.net/showthread.php?t=99570)

vermillioN25 08-07-2009 01:06

What's wrong with my code?
 
Hi. I'm trying to create a new Jailmod. A JailMod that works and its free. But I'm new at pawn/amx scripting, and I really don't know what to do. How it should be?

Description: At the start of the round, I wanted to check if the player are CT. If yes, then give him M4A1, etc... If not, then strip weapons and give a knife. And at the end of the round, it will strip weapons and give a knife :)

Here is my code:

PHP Code:

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

#define PLUGIN "JailMod"
#define VERSION "1.0"
#define AUTHOR "elemeNt;"

new amx_gamename

enum CsTeams 
{
    
CS_TEAM_UNASSIGNED 0,
    
CS_TEAM_T 1,
    
CS_TEAM_CT 2,
    
CS_TEAM_SPECTATOR 3
};


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("HLTV""event_new_round""a""1=0""2=0")  
    
amx_gamename register_cvar"amx_gamename""JailMod 1.0" ); 
    
register_logevent("logevent_round_end"2"1=Round_End")  
    
}

public 
event_new_round()
{
    if (
CS_GET_USER_TEAM == 2)
    {
        
strip_user_weapons (id)
        
give_item(id,"weapon_m4a1")
        
give_item(id,"ammo_556nato")
        
give_item(id,"ammo_556nato")
        
give_item(id,"ammo_556nato")
        
give_item(id,"weapon_deagle")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"weapon_knife")
        
give_item(id,"weapon_hegrenade")
    }
    else
    {
        
strip_user_weapons (id)
        
give_item(id,"weapon_knife")
    }
    return 
PLUGIN_CONTINUE
}

public 
logevent_round_end()
{
        
strip_user_weapons (id)
        
give_item(id,"weapon_knife")


And I'm getting this errors:

Quote:

//AMXXPC compile.exe
// by the AMX Mod X Dev Team

//// jailmod.sma
// C:\Program Files\Valve\HLServer\cstrike\addons\amxmodx\s cripting\jailmod.sma(
14) : warning 201: redefinition of constant/macro (symbol "CsTeams")
// C:\Program Files\Valve\HLServer\cstrike\addons\amxmodx\s cripting\jailmod.sma(
32) : error 017: undefined symbol "CS_GET_USER_TEAM"
// C:\Program Files\Valve\HLServer\cstrike\addons\amxmodx\s cripting\jailmod.sma(
34) : error 017: undefined symbol "id"
// C:\Program Files\Valve\HLServer\cstrike\addons\amxmodx\s cripting\jailmod.sma(
35) : error 017: undefined symbol "id"
// C:\Program Files\Valve\HLServer\cstrike\addons\amxmodx\s cripting\jailmod.sma(
35) : warning 215: expression has no effect
// C:\Program Files\Valve\HLServer\cstrike\addons\amxmodx\s cripting\jailmod.sma(
35) : error 001: expected token: ";", but found ")"
// C:\Program Files\Valve\HLServer\cstrike\addons\amxmodx\s cripting\jailmod.sma(
35) : error 029: invalid expression, assumed zero
// C:\Program Files\Valve\HLServer\cstrike\addons\amxmodx\s cripting\jailmod.sma(
35) : fatal error 107: too many error messages on one line
//
// Compilation aborted.
// 6 Errors.
// Could not locate output file compiled\jailmod.amx (compile failed).
//
// Compilation Time: 0,11 sec
// ----------------------------------------
NOTE: This is my first try. Please, don't humiliate me, I'm learning it.

fysiks 08-07-2009 01:20

Re: What's wrong with my code?
 
Round End and New Round events are global. They don't act on any one person. (i.e. you can't just use "id" and expect it to work, you need to get it defined first)

I suggest making a simple test plugin first. Somebody else might be able to help you with your current endeavor however.

Arkshine 08-07-2009 02:13

Re: What's wrong with my code?
 
It won't work, like fysiks said it's global events, you can not pass the id like that. You have to loop through all players.

Alucard^ 08-07-2009 04:30

Re: What's wrong with my code?
 
Maybe something like this:

PHP Code:

#include <amxmodx>
#include <fun>

#define PLUGIN "JailMod"
#define VERSION "1.0"
#define AUTHOR "elemeNt;"

new g_MaxPlayers

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("HLTV""event_new_round""a""1=0""2=0")   
    
register_logevent("logevent_round_end"2"1=Round_End")  
    
    
g_MaxPlayers get_maxplayers()
}

public 
event_new_round()
{
    for(new 
i=1i<=g_MaxPlayersi++)
    {
        if(
is_user_alive(i) )
        {
            if (
get_user_team(i) == 2)
            {
                
strip_user_weapons(i)
                
give_item(i,"weapon_m4a1")
                
give_item(i,"ammo_556nato")
                
give_item(i,"ammo_556nato")
                
give_item(i,"ammo_556nato")
                
give_item(i,"weapon_deagle")
                
give_item(i,"ammo_50ae")
                
give_item(i,"ammo_50ae")
                
give_item(i,"ammo_50ae")
                
give_item(i,"ammo_50ae")
                
give_item(i,"ammo_50ae")
                
give_item(i,"ammo_50ae")
                
give_item(i,"ammo_50ae")
                
give_item(i,"weapon_knife")
                
give_item(i,"weapon_hegrenade")
            }
            else
            {
                
strip_user_weapons(i)
                
give_item(i,"weapon_knife")
            }
        }
    } 
    return 
PLUGIN_CONTINUE
}

public 
logevent_round_end()
{
    for(new 
i=1i<=g_MaxPlayersi++)
    {
        if(
is_user_alive(i) )
        {
            
strip_user_weapons (i)
            
give_item(i,"weapon_knife")
        }
    }    



Arkshine 08-07-2009 04:36

Re: What's wrong with my code?
 
Yes more like that, though you could use the cs native to give ammos.

vermillioN25 08-07-2009 09:44

Re: What's wrong with my code?
 
Really thank you guys :)

Alucard, thank you, but I think there is something wrong. In new round, I don't get m4a1 and either my knife get stripped.

Should I use Ham with Player Spawn + if (get_user_team(i) == 2) ?

//EDIT

I tested it with HamSandWich and it worked :D
here is the code:

PHP Code:

#include <amxmodx>
#include <fun>
#include <hamsandwich>

#define PLUGIN "JailMod"
#define VERSION "1.0"
#define AUTHOR "elemeNt;"

new g_MaxPlayers

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""fwHamPlayerSpawnPost"1)  
    
register_logevent("logevent_round_end"2"1=Round_End")  
    
    
g_MaxPlayers get_maxplayers()
}

public 
fwHamPlayerSpawnPost(iPlayer)
{
    for(new 
i=1i<=g_MaxPlayersi++)
    {
        if(
is_user_alive(i) )
        {
            if (
get_user_team(i) == 2)
            {
            
strip_user_weapons(i)
            
give_item(i,"weapon_m4a1")
            
give_item(i,"ammo_556nato")
            
give_item(i,"ammo_556nato")
            
give_item(i,"ammo_556nato")
            
give_item(i,"weapon_deagle")
            
give_item(i,"ammo_50ae")
            
give_item(i,"ammo_50ae")
            
give_item(i,"ammo_50ae")
            
give_item(i,"ammo_50ae")
            
give_item(i,"ammo_50ae")
            
give_item(i,"ammo_50ae")
            
give_item(i,"ammo_50ae")
            
give_item(i,"weapon_knife")
            
give_item(i,"weapon_hegrenade")
            }
            else
            {
            
strip_user_weapons(i)
            
give_item(i,"weapon_knife")
            }
        }
    } 
    return 
PLUGIN_CONTINUE
}

public 
logevent_round_end()
{
    for(new 
i=1i<=g_MaxPlayersi++)
    {
        if(
is_user_alive(i) )
        {
        
strip_user_weapons (i)
        
give_item(i,"weapon_knife")
        }
    }    


Thanks to alucard and arkshine

Bugsy 08-07-2009 11:14

Re: What's wrong with my code?
 
If you do it that way then you can use the player id in the hamsandwich forward.

PHP Code:

public fwHamPlayerSpawnPostiPlayer )
{
    if( 
is_user_aliveiPlayer ) )
    {
        if ( 
get_user_teamiPlayer ) == )
        {
            
strip_user_weaponsiPlayer )
            
give_item(iPlayer,"weapon_m4a1")
            
give_item(iPlayer,"ammo_556nato")
            
give_item(iPlayer,"ammo_556nato")
            
give_item(iPlayer,"ammo_556nato")
            
give_item(iPlayer,"weapon_deagle")
            
give_item(iPlayer,"ammo_50ae")
            
give_item(iPlayer,"ammo_50ae")
            
give_item(iPlayer,"ammo_50ae")
            
give_item(iPlayer,"ammo_50ae")
            
give_item(iPlayer,"ammo_50ae")
            
give_item(iPlayer,"ammo_50ae")
            
give_item(iPlayer,"ammo_50ae")
            
give_item(iPlayer,"weapon_knife")
            
give_item(iPlayer,"weapon_hegrenade")
        }
        else
        {
            
strip_user_weapons(iPlayer)
            
give_item(iPlayer,"weapon_knife")
        }
    } 



xPaw 08-07-2009 11:47

Re: What's wrong with my code?
 
Small improve :0
PHP Code:

public fwHamPlayerSpawnPostiPlayer )
{
    if( 
is_user_aliveiPlayer ) )
    {
        
strip_user_weaponsiPlayer )
        
give_itemiPlayer,"weapon_knife" )
        
        if ( 
get_user_teamiPlayer ) == )
        {
            
give_itemiPlayer,"weapon_m4a1" )
            
give_itemiPlayer,"ammo_556nato" )
            
give_itemiPlayer,"ammo_556nato" )
            
give_itemiPlayer,"ammo_556nato" )
            
give_itemiPlayer,"weapon_deagle" )
            
give_itemiPlayer,"ammo_50ae" )
            
give_itemiPlayer,"ammo_50ae" )
            
give_itemiPlayer,"ammo_50ae" )
            
give_itemiPlayer,"ammo_50ae" )
            
give_itemiPlayer,"ammo_50ae" )
            
give_itemiPlayer,"ammo_50ae" )
            
give_itemiPlayer,"ammo_50ae" )
            
give_itemiPlayer,"weapon_hegrenade" )
        }
    } 



vermillioN25 08-07-2009 12:01

Re: What's wrong with my code?
 
Thank you Bugsy. Thank you xPaw :D

I have a question: I tested this plugin alone (only me in the server). I called a friend to help me testing, and when he connects (not spawn) my weapons are stripped and i get again M4A1, and etc. How do I fix it?

xPaw 08-07-2009 12:27

Re: What's wrong with my code?
 
show new code please


All times are GMT -4. The time now is 18:24.

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