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

What's wrong with my code?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vermillioN25
Member
Join Date: Apr 2009
Location: Brazil
Old 08-07-2009 , 01:06   What's wrong with my code?
Reply With Quote #1

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.
__________________

Last edited by vermillioN25; 08-07-2009 at 01:14.
vermillioN25 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-07-2009 , 01:20   Re: What's wrong with my code?
Reply With Quote #2

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.
__________________
fysiks is offline
Old 08-07-2009, 02:05
Demigod90
This message has been deleted by Demigod90. Reason: useless :x
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-07-2009 , 02:13   Re: What's wrong with my code?
Reply With Quote #3

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.
__________________
Arkshine is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 08-07-2009 , 04:30   Re: What's wrong with my code?
Reply With Quote #4

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

__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-07-2009 , 04:36   Re: What's wrong with my code?
Reply With Quote #5

Yes more like that, though you could use the cs native to give ammos.
__________________
Arkshine is offline
vermillioN25
Member
Join Date: Apr 2009
Location: Brazil
Old 08-07-2009 , 09:44   Re: What's wrong with my code?
Reply With Quote #6

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
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
__________________

Last edited by vermillioN25; 08-07-2009 at 10:10. Reason: code worked
vermillioN25 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-07-2009 , 11:14   Re: What's wrong with my code?
Reply With Quote #7

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

__________________
Bugsy is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 08-07-2009 , 11:47   Re: What's wrong with my code?
Reply With Quote #8

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

__________________
xPaw is offline
vermillioN25
Member
Join Date: Apr 2009
Location: Brazil
Old 08-07-2009 , 12:01   Re: What's wrong with my code?
Reply With Quote #9

Thank you Bugsy. Thank you xPaw

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?
__________________

Last edited by vermillioN25; 08-07-2009 at 12:08.
vermillioN25 is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 08-07-2009 , 12:27   Re: What's wrong with my code?
Reply With Quote #10

show new code please
__________________
xPaw is offline
Reply


Thread Tools
Display Modes

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 10:43.


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