Raised This Month: $203 Target: $400
 50% 

ArrayGetString


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cristian505
Member
Join Date: Oct 2020
Location: Romania
Old 09-15-2021 , 11:31   ArrayGetString
Reply With Quote #1

Base:
Code:
new MaxClasses = 0, Array:ZombieName, ZombieNameReal[33];

public plugin_init()
{
    register_plugin(NAME, VERSION, AUTHOR);

    //Ham
    RegisterHam(Ham_Spawn, "player", "Player_Spawn", 1);
}

public plugin_precache()
{
    ZombieName = ArrayCreate(32, 1);
}

public plugin_natives()
{
    register_native("us_register_zombie_class", "us_register_zombie_class_native");
}

public Player_Spawn(id)
{
    if(!is_user_alive(id)) return;

    ZombieNameReal[id] = 0;

    new Name[32]; ArrayGetString(ZombieName, ZombieNameReal[id], Name, sizeof(Name));
    client_print(0, print_chat, Name);
}

public us_register_zombie_class_native(const Name[])
{
    ArrayPushString(ZombieName, Name);

    MaxClasses++;
}
Test Class:
Code:
#include <amxmodx>
#include <us>

public plugin_init()
{
    us_register_zombie_class("Armoredddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");
}
Inc:
Code:
native us_register_zombie_class(const Name[])
If it works it should show me that name in chat but no work and i don't receive any error in console...
Cristian505 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-15-2021 , 12:20   Re: ArrayGetString
Reply With Quote #2

This is not how you pass strings around with natives. You have to use get_string and set_string
http://amxmodx.org/api/amxmodx/get_string
http://amxmodx.org/api/amxmodx/set_string

In your case get_string should be what you want. Also MaxClasses is not needed, you can get the current number of classes by using ArraySize(ZombieName).
PHP Code:
ArrayGetString(ZombieNameZombieNameReal[id], Namesizeof(Name)) 
This is also wrong, you should use charsmax for strings, not sizeof. Otherwise, you risk not having space for the null terminator.
__________________

Last edited by HamletEagle; 09-15-2021 at 12:22.
HamletEagle is offline
Cristian505
Member
Join Date: Oct 2020
Location: Romania
Old 09-15-2021 , 12:39   Re: ArrayGetString
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
This is not how you pass strings around with natives. You have to use get_string and set_string
http://amxmodx.org/api/amxmodx/get_string
http://amxmodx.org/api/amxmodx/set_string

In your case get_string should be what you want. Also MaxClasses is not needed, you can get the current number of classes by using ArraySize(ZombieName).
PHP Code:
ArrayGetString(ZombieNameZombieNameReal[id], Namesizeof(Name)) 
This is also wrong, you should use charsmax for strings, not sizeof. Otherwise, you risk not having space for the null terminator.
Ro: Nu credeam ca exista asa ceva. Dupa ce termin temele o sa incerc nativele alea.
En: I didn't thought something like this exist.After finish homework i will try thos natives.
Cristian505 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 22:53.


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