Raised This Month: $51 Target: $400
 12% 

a few questions (CS:S)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stas3
Junior Member
Join Date: Jul 2011
Location: ukraine
Old 07-05-2011 , 07:03   a few questions (CS:S)
Reply With Quote #1

I started studying SourcePawn and I am having some issues:

1.

There are global variables: MAX_NAME_LENGTH, MaxClients, MAX_TARGET_LENGTH, MAXPLAYERS .. What is more? Where is their list?

2.

decl string:weapon[32];
GetClientWeapon(client, weapon, sizeof(weapon));

It's not very convenient for me because always need to specify the size of the string. Is there a list of recommended values for certain rows? For example, player_say, "text" - what value? Etc.

3.

I'm already tired of the error when compiling: "Warning 213: tag mismatch" (although the script works)

PHP Code:
#include <sourcemod>

public OnPluginStart()
{
    
HookEvent("player_say"PlayerSay);
}

public 
Action:PlayerSay(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    new 
string:msg[128];
    
GetEventString(event"text"msgsizeof(msg));
    if (
StrEqual(msg"1")) {
        
decl string:weapon[32];
        
GetClientWeapon(clientweaponsizeof(weapon));
        
PrintToChatAll("%s"weapon);
    }

4.

When you need to do so: new Handle:var; ?

Last edited by stas3; 07-05-2011 at 07:11.
stas3 is offline
SideX
Senior Member
Join Date: Jun 2010
Location: Ukraine, Melitopol.
Old 07-05-2011 , 13:42   Re: a few questions (CS:S)
Reply With Quote #2

3)
PHP Code:
#include <sourcemod> 

public OnPluginStart() 

    
HookEvent("player_say"PlayerSay); 


public 
Action:PlayerSay(Handle:event, const String:name[], bool:dontBroadcast

    new 
client GetClientOfUserId(GetEventInt(event"userid")); 
    new 
String:msg[128]; 
    
GetEventString(event"text"msgsizeof(msg)); 
    if (
StrEqual(msg"1")) { 
        
decl String:weapon[32]; 
        
GetClientWeapon(clientweaponsizeof(weapon)); 
        
PrintToChatAll("%s"weapon); 
    } 

You must specify type of the variable correctly (string and String - different)
SideX is offline
stas3
Junior Member
Join Date: Jul 2011
Location: ukraine
Old 07-05-2011 , 14:01   Re: a few questions (CS:S)
Reply With Quote #3

Thanks, I understand. How about the other issues? And one more thing that bothers me. Array stores the data of one type, but what if I need to store multiple values for the players (as a dictionary in Python)

In python this is simple:

Quote:
mydict = {}
client_index = 1
mydict[client_index] = {'name': 'Jon', 'years': 5}

mydict[client_index]['name'] // Jon
mydict[client_index]['years'] // 5
How to do the same in SourcePawn, it's unclear to me.
__________________
My English is bad

Last edited by stas3; 07-05-2011 at 14:31.
stas3 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-05-2011 , 14:44   Re: a few questions (CS:S)
Reply With Quote #4

Quote:
Originally Posted by stas3 View Post
I started studying SourcePawn and I am having some issues:

1.

There are global variables: MAX_NAME_LENGTH, MaxClients, MAX_TARGET_LENGTH, MAXPLAYERS .. What is more? Where is their list?
The globals that exist depend entirely on which .inc files you have loaded. The default, sourcemod.inc, loads a bunch of additional inc files.

The API documentation usually lists the globals for each inc. file when you click on it in the left list, but sometimes you have to click the File link near the upper-right to see them.

Quote:
Originally Posted by stas3 View Post
2.

decl string:weapon[32];
GetClientWeapon(client, weapon, sizeof(weapon));

It's not very convenient for me because always need to specify the size of the string. Is there a list of recommended values for certain rows? For example, player_say, "text" - what value? Etc.
Some strings have recommended sizes, but most don't. For example, MAX_NAME_LENGTH is used if you're getting a player's name via GetClientName

Quote:
Originally Posted by stas3 View Post
4.

When you need to do so: new Handle:var; ?
Handles are a type-safe handle to data on the C++ side (see: SourceMod Extensions). Usually, the API documentation tells you which functions return a handle. Passing the wrong type of handle to a native will throw an error at runtime.

The Wiki talks about the types of Handles, although last time I checked, it was missing one or two.

As for dictionaries, Pawn doesn't really support them. There are two ways to fake them (more or less). One is to (ab)use enums. The other is to use an adt_array of adt_tries.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
stas3
Junior Member
Join Date: Jul 2011
Location: ukraine
Old 07-05-2011 , 15:17   Re: a few questions (CS:S)
Reply With Quote #5

Thanks, I'll experiment.
__________________
My English is bad
stas3 is offline
SideX
Senior Member
Join Date: Jun 2010
Location: Ukraine, Melitopol.
Old 07-06-2011 , 12:15   Re: a few questions (CS:S)
Reply With Quote #6

Quote:
Originally Posted by stas3 View Post
Thanks, I understand. How about the other issues? And one more thing that bothers me. Array stores the data of one type, but what if I need to store multiple values for the players (as a dictionary in Python)
As I know, u can't store multiple values with a different type in one array.
SideX is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-06-2011 , 12:54   Re: a few questions (CS:S)
Reply With Quote #7

Quote:
Originally Posted by SideX View Post
As I know, u can't store multiple values with a different type in one array.
You can, however, with a Trie.

A Trie can be used as a simple-man's object by having differently named elements of different types.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
stas3
Junior Member
Join Date: Jul 2011
Location: ukraine
Old 07-06-2011 , 19:01   Re: a few questions (CS:S)
Reply With Quote #8

PHP Code:
#include <sourcemod>

new var[MAXPLAYERS 1];

public 
OnPluginStart()
{
    
HookEvent("player_spawn"PlayerSpawn);
}

public 
Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
GetClientTeam(client) > 1) {
        var[
client] += 1;
        
PrintToChat(client"spawns = %d", var[client]);
    }
}

public 
OnClientPutInServer(client)
{
    var[
client] = 0;

new var[MAXPLAYERS + 1]; - If my server is 10 slots, We get 55 unwanted cells. It would be easier new var[MaxClients + 1];. I understand this is due to the fact that MaxClients is only available after OnPluginStart(). From here I have a question: "Is it possible to create global variables within functions?"

Python so simple in comparison with SourcePawn, there is simply:

PHP Code:
def myfunc():
    global var
    var = 

__________________
My English is bad
stas3 is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 07-06-2011 , 19:33   Re: a few questions (CS:S)
Reply With Quote #9

You can use the "static" keyword, you can use MaxClients with it:

PHP Code:
static var[MaxClients+1]; 
If you need to access the variable in different functions you could use an ADT array.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
stas3
Junior Member
Join Date: Jul 2011
Location: ukraine
Old 07-07-2011 , 19:41   Re: a few questions (CS:S)
Reply With Quote #10

Why PrintToChat sends the same message twice? (and PrintToChatAll). And I have not found the normal commands to work with indices of objects. For example, I need to remove all weapons from the ground. Or get a list of indexes of certain objects.

In Eventscripts it this way:

Quote:
es.createentityindexlist('weapon_awp')
I've heard that SourceMod more features, but I still do not feel this.
__________________
My English is bad

Last edited by stas3; 07-07-2011 at 20:20.
stas3 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 12:34.


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