AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hit a wall, read through funcs and stuff before post (https://forums.alliedmods.net/showthread.php?t=146731)

Len 12-31-2010 10:42

Hit a wall, read through funcs and stuff before post
 
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



Len 12-31-2010 14:03

Re: Hit a wall, read through funcs and stuff before post
 
40 views and no one has bothered to leave a comment :down: 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.

wrecked_ 12-31-2010 14:41

Re: Hit a wall, read through funcs and stuff before post
 
  • 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".

Len 12-31-2010 14:51

Re: Hit a wall, read through funcs and stuff before 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?

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 :wink:

wrecked_ 12-31-2010 15:04

Re: Hit a wall, read through funcs and stuff before post
 
Quote:

Originally Posted by Len (Post 1383267)
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 (Post 1383267)
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 (Post 1383267)
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 :wink:

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.

Len 12-31-2010 16:13

Re: Hit a wall, read through funcs and stuff before post
 
amxx took my API virginity :D, 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

wrecked_ 12-31-2010 16:24

Re: Hit a wall, read through funcs and stuff before post
 
Quote:

Originally Posted by Len (Post 1383297)
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 (Post 1383297)
thank you so much wrecked

Not a problem.

Quote:

Originally Posted by Len (Post 1383297)
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. :wink:

Exolent[jNr] 12-31-2010 17:06

Re: Hit a wall, read through funcs and stuff before post
 
Quote:

Originally Posted by wrecked_ (Post 1383304)
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.

Len 12-31-2010 17:16

Re: Hit a wall, read through funcs and stuff before post
 
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

wrecked_ 12-31-2010 17:24

Re: Hit a wall, read through funcs and stuff before post
 
Quote:

Originally Posted by Exolent[jNr] (Post 1383334)
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. :wink:


All times are GMT -4. The time now is 02:12.

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