Raised This Month: $ Target: $400
 0% 

Hit a wall, read through funcs and stuff before post


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Len
Senior Member
Join Date: Dec 2007
Old 12-31-2010 , 10:42   Hit a wall, read through funcs and stuff before post
Reply With Quote #1

Server says im flooding and join teams doesn't work lol, im new to pawn/small amxmodx my logic here is prob wrong is there anyone that can help me out thank you
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#define PLUGIN "Basics"
#define VERSION "1.0"
#define AUTHOR "Hihiyoyo"
 
public plugin_init() {
 
register_plugin(PLUGINVERSIONAUTHOR)
 
register_clcmd("say""rules")
 
register_clcmd("jointeam""block_jointeam")
}
public 
rules(id) {
 new 
command[6]
 new 
message[200]
 
read_argv(1message201)
 
client_cmd(id"say message")
 
read_argv(2command6)
 if (
equali(command"/rules"6)) {
  new 
name[31]
  
get_user_name(idname30)
  
client_print(idprint_chat"name The rules are..")
 }
 return 
PLUGIN_HANDLED
}
public 
block_jointeam(id) {
 if (
cs_get_user_team(id) != CS_TEAM_SPECTATOR)
 return 
PLUGIN_HANDLED
 
else {
 new 
team[1]
 
read_argv(1team1)
 if (
team[0] == 1)
 
client_cmd(id"jointeam 1")
 else if (
team[0] == 2)
 
client_cmd(id"jointeam 2")
 else
 
client_cmd(id"jointeam 3")
 }
 return 
PLUGIN_HANDLED


Last edited by Len; 12-31-2010 at 13:42. Reason: script editted, found some things out myself
Len is offline
Len
Senior Member
Join Date: Dec 2007
Old 12-31-2010 , 14:03   Re: Hit a wall, read through funcs and stuff before post
Reply With Quote #2

40 views and no one has bothered to leave a comment how hard can it be to just say....
oh look ur syntax or logic is wrong or this ".." doesn't work like that for example
I've read some of the tutorials
http://wiki.alliedmods.net/index.php/Pawn_Tutorial
http://wiki.alliedmods.net/Advanced_...X_Mod_X)#Tasks
and used http://www.amxmodx.org/funcwiki.php
so it isn't through lazyness I can't get this to work.. so please be kind enough to leave a helpfull comment or suggestion.
Len is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 12-31-2010 , 14:41   Re: Hit a wall, read through funcs and stuff before post
Reply With Quote #3

  • Get off IE and use a different browser. IE often causes shitty indentation when posting code snippets, as shown above. This is probably why no one bothered to read it.
  • In your jointeam function you make the "array" one-celled. This will not store any information, as one cell is needed for nullification. Change it to two cells at the very least.
  • When comparing the jointeam argument you use integers instead of characters. You must either compare them to characters or convert the array cell to an integer.
  • In your rules function, you store their name in a string. To insert this into a message to the client, you must do something like this:
    Code:
    // BAD client_print( id, print_chat, "name The rules are.." ) // GOOD client_print( id, print_chat, "%s The rules are..", name )
    Multiple examples of this can be found around the fora.
  • Half of your rules function is unnecessary. Instead of hooking say and catching if the client has said /rules after it, just change the hook to catch "say /rules".
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Len
Senior Member
Join Date: Dec 2007
Old 12-31-2010 , 14:51   Re: Hit a wall, read through funcs and stuff before post
Reply With Quote #4

Thank you and I'll use firefox next time, nullification so team[0] would be 'null' and team[1] = what I set it to right?

When comparing the jointeam argument you use integers instead of characters. You must either compare them to characters or convert the array cell to an integer.

so either I set team[1] to a/b/c or convert them to numbers? it would be in ascii right? so what will I have to use to convert them, or is there another method to store numbers without converting etc

I plan on adding other say commands in the same plugin to compact it abit for when I make my other plugins which is why I've gone the long way round
Len is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 12-31-2010 , 15:04   Re: Hit a wall, read through funcs and stuff before post
Reply With Quote #5

Quote:
Originally Posted by Len View Post
Thank you and I'll use firefox next time, nullification so team[0] would be 'null' and team[1] = what I set it to right?
If you did something like this
Code:
new team[2] read_argv( 1, team, 1 ) // then team[0] = the character value of the team theyre trying to join team[1] = 0 aka null

Quote:
Originally Posted by Len View Post
so either I set team[1] to a/b/c or convert them to numbers? it would be in ascii right? so what will I have to use to convert them, or is there another method to store numbers without converting etc
Characters are not always letters. '1' is a character, '2' is a character, etc.

Simply:
Code:
if( team[0] == 1 ) // change to if( team[0] == '1' )

Quote:
Originally Posted by Len View Post
I plan on adding other say commands in the same plugin to compact it abit for when I make my other plugins which is why I've gone the long way round
It is still much better to use the way I recommended as a beginner. The way it is at the moment, it is being done incorrectly and is just more confusing than helpful to most.

This is a VERY common misconception to most beginners. Often it is perceived that it is much nicer and more stylistic to compact everything, being able to add things in whenever you decide to make a new command. There is nothing wrong with registering new clcmds and though it may be more efficient (not even sure about that one), it is more confusing for you and you should not try doing this until you have learned the basics. No one will scold you for having many clcmds.

I can tell you'll like API's. ;)


EDIT: Also, in jointeam use the argument of 1 to get the team #, as 0 is the actual jointeam command itself.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Len
Senior Member
Join Date: Dec 2007
Old 12-31-2010 , 16:13   Re: Hit a wall, read through funcs and stuff before post
Reply With Quote #6

amxx took my API virginity , not so much now but the possibilities of what I'll be able to do with my favourite game!

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#define PLUGIN "Basics"
#define VERSION "1.0"
#define AUTHOR "Hihiyoyo"
 
public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /rules""rules")
    
register_clcmd("jointeam""block_jointeam")
}
public 
rules(id) {
    new 
message[1000]
    
read_argv(1message1000)
    
client_print(idprint_chat"%s : /rules"name)
    new 
name[31]
    
get_user_name(idname30)
    
client_print(idprint_chat"%s The rules are.."name)
    return 
PLUGIN_HANDLED
}
public 
block_jointeam(id) {
    
client_print(idprint_chat"test")
    
client_print(idprint_chat"team = %s"cs_get_user_team(id))
    
    if (
cs_get_user_team(id) != CS_TEAM_SPECTATOR && 
    !
cs_get_user_team(id) &&
    
cs_get_user_team(id) != CS_TEAM_UNASSIGNED) return PLUGIN_HANDLED
    
    
else {
    
    new 
team[2]
    
read_argv(1team1)
    
client_print(idprint_chat"0 = %s",  team[0])
    
    if (
team[0] == '1'cs_set_user_team(idCS_TEAM_T)
    
    else if (
team[0] == '2'cs_set_user_team(idCS_TEAM_CT)
    
    else 
cs_set_user_team(idCS_TEAM_SPECTATOR)

    }
    return 
PLUGIN_HANDLED

I did your suggestions and changed a few things like client_cmd which was just making endless loops :@
debug results:
test
team =
0 = 3
which tells me cs_get_user_team isn't returning anything at all, not what func wiki says, thank you so much wrecked

EDIT: Also, in jointeam use the argument of 1 to get the team #, as 0 is the actual jointeam command itself.
so team[0] = jointeam, team[1] = team, team[2] = null? my debug comes out fine with the team numbers though

Last edited by Len; 12-31-2010 at 16:20. Reason: slight mistake
Len is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 12-31-2010 , 16:24   Re: Hit a wall, read through funcs and stuff before post
Reply With Quote #7

Quote:
Originally Posted by Len View Post
I did your suggestions and changed a few things like client_cmd which was just making endless loops :@
debug results:
test
team =
0 = 3
which tells me cs_get_user_team isn't returning anything at all, not what func wiki says,
It does return a value, but it is returning an integer value. You are using %s, which is used to format a string. To insert the value returned by cs_get_user_team() you'd use %i or %d.

A full list:
  • %s - string
  • %d - integer
  • %i - integer
  • %f - float
    • %.2f - float to the 2nd decimal place
    • %.3f - float to the 3rd decimal place
    • etc...

Quote:
Originally Posted by Len View Post
thank you so much wrecked
Not a problem.

Quote:
Originally Posted by Len View Post
so team[0] = jointeam, team[1] = team, team[2] = null?
By argument, I was referring to the 1st parameter of read_argv in the jointeam function, but it seems you've fixed that on your own. So in that case, just ignore what I said.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-31-2010 , 17:06   Re: Hit a wall, read through funcs and stuff before post
Reply With Quote #8

Quote:
Originally Posted by wrecked_ View Post
A full list:
  • %s - string
  • %d - integer
  • %i - integer
  • %f - float
    • %.2f - float to the 2nd decimal place
    • %.3f - float to the 3rd decimal place
    • etc...
Not even close.
http://www.cplusplus.com/reference/c...cstdio/printf/

The * is probably the coolest thing I've seen for formatting.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Len
Senior Member
Join Date: Dec 2007
Old 12-31-2010 , 17:16   Re: Hit a wall, read through funcs and stuff before post
Reply With Quote #9

PHP Code:
/* Plugin generated by AMXX-Studio */

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

#define PLUGIN "Basics"
#define VERSION "1.0"
#define AUTHOR "Hihiyoyo"
 
public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /rules""rules")
    
register_clcmd("jointeam""block_jointeam")
}
public 
rules(id) {
    new 
message[1001]
    
read_argv(1message1000)
    new 
name[31]
    
get_user_name(idname30)
    
client_print(idprint_chat"%s : /rules"name)
    
client_print(idprint_chat"%s The rules are.."name)
    return 
PLUGIN_HANDLED
}
public 
block_jointeam(id) {
    
client_print(idprint_chat"test")
    
client_print(idprint_chat"theteam = %i"cs_get_user_team(id))
    
    if (
cs_get_user_team(id) < '3' &&
    
cs_get_user_team(id) > '0') return PLUGIN_HANDLED
    
    
else {
    
    new 
team[2]
    
read_argv(1team1)
    
client_print(idprint_chat"0 = %s",  team[0])
    
    if (
team[0] == '1'cs_set_user_team(idCS_TEAM_T)
    
    else if (
team[0] == '2'cs_set_user_team(idCS_TEAM_CT)

    else if (
team[0] == '3'cs_set_user_team(idCS_TEAM_SPECTATOR)
    }
    return 
PLUGIN_HANDLED

the only problem is I now need to spawn my players! <ns> is no longer available as that was what I was going to use the spawn it offers in func wiki, but it just makes my plugin a bad load! I had a skim through an couldn't see much in the way of spawning any suggestions

cs_set_user_team was returning 0 (no team choosen) 1 Terrorist, 2 CT, 3 Spec

edit: found cs_user_spawn skimmed past it

Last edited by Len; 12-31-2010 at 17:26.
Len is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 12-31-2010 , 17:24   Re: Hit a wall, read through funcs and stuff before post
Reply With Quote #10

Quote:
Originally Posted by Exolent[jNr] View Post
Not even close.
http://www.cplusplus.com/reference/c...cstdio/printf/

The * is probably the coolest thing I've seen for formatting.
I stand corrected. p is specific to C++ but this list seems to have everything.

Never knew about the e's, those sound like they'd be cool.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Reply



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 02:12.


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