AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Can I create new entity with property in Game Engine using AMXX (https://forums.alliedmods.net/showthread.php?t=326646)

LiZou Mapper 08-10-2020 04:21

Can I create new entity with property in Game Engine using AMXX
 
2 Attachment(s)
Hello :)
So, I try create new entities to use that in maps (mapping), entity when triggered print message in chat !
But it's not work, when connected server,when triggered it
Create entity in the information's
classname : game_cprinter
keyValue :
targetname : Name
message : Message
spawnflags:
1:All Players
2:Remove On fire

PHP Code:

/*
    Classname : game_cprinter 
    Role : Print Message in chat !

    KeyValue :
        targetname : Name 
        message : Message 

    Spawn Flags : 
        1: All Players
        2: Remove On fire
*/

#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
// #include <reapi>

public plugin_init()
{
    
// Load Plugin
    
register_plugin("[Entity] Game Chat Printer""1.0""LiZou Mapper")

    
// Ham
    
RegisterHam(Ham_Use"game_cprinter""CGameChatPrinter")
}

public 
CGameChatPrinter(const Entity, const Activator)
{
    new 
Message/*, Spawnflags*/

    // Get message from entity 
    // get_entvar(Entity, var_message, Message)
    // get_entvar(Entity, var_spawnflags, Spawnflags)
    
pev(Entitypev_messageMessage)

    
// Print message for all players ! 
    
client_print_color(0print_chat"%s"Message)
}

/*
stock mapper_remove_entity(const Entity)
{
        // Remove entity from map !
    engfunc(EngFunc_RemoveEntity, Entity)
}
*/ 

but when connected server, i see it in console !
Code:

L 08/10/2020 - 07:56:51: [HAMSANDWICH] Failed to retrieve classtype for "game_cprinter", hook for "CGameChatPrinter" not active.
L 08/10/2020 - 07:56:51: [AMXX] Run time error 10 (plugin "entity_game_cprinter.amxx") (native "RegisterHam") - debug not enabled!
L 08/10/2020 - 07:56:51: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quote

You can see photo's

Shadows Adi 08-10-2020 07:20

Re: Problem with hamsandwich ham_use !
 
I assume that your entity class is a button, so you need to register your ham func as a post function, because the message is triggered AFTER you pressed that button.
btw, I see you tried to make it with reAPI, so, you can try also engine's register_think():
register_think(const Classname[], const function[]);

LiZou Mapper 08-10-2020 17:13

Re: Problem with hamsandwich ham_use !
 
Quote:

Originally Posted by Shadows Adi (Post 2713733)
I assume that your entity class is a button, so you need to register your ham func as a post function, because the message is triggered AFTER you pressed that button.
btw, I see you tried to make it with reAPI, so, you can try also engine's register_think():
register_think(const Classname[], const function[]);

Not exactly, from func_button can be triggered entity from another entity For example:
trigger_multiple or trigger_relay or func_door, the important when entity triggered from another entity :)

LiZou Mapper 08-10-2020 17:29

Re: Problem with hamsandwich ham_use !
 
Quote:

Originally Posted by Shadows Adi (Post 2713733)
I assume that your entity class is a button, so you need to register your ham func as a post function, because the message is triggered AFTER you pressed that button.
btw, I see you tried to make it with reAPI, so, you can try also engine's register_think():
register_think(const Classname[], const function[]);

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <reapi>

public plugin_init()
{
    
// Load plugin 
    
register_plugin("[Entity] Chat Printer""1.0""LiZou Mapper")

    
// Think 
    
register_think("game_cprinter""CGameChatPrinter")
}

public 
CGameChatPrinter(Entity)
{
    new 
MessageSpawnflags
    
// Get message from entity 
    
get_entvar(Entityvar_messageMessage)

    
// Get spawnflag from entity 
    // get_entvar(Entity, var_spawnflags, Spawnflags)

    
client_print_color(0print_chat"%s"Message)

    
// Print chat for player 
    /*if(Spawnflags == 0)
        client_print_color(Entity, print_chat, "%s", Message)

    if(Spawnflags & 1)
        client_print_color(0, print_chat, "%s", Message)

    if(Spawnflags & 2)
        Util_RemoveEntity(Entity)*/
}

public 
Util_RemoveEntity(const Entity)
{
    
engfunc(EngFunc_RemoveEntityEntity)


Not work !

Natsheh 08-10-2020 20:29

Re: Problem with hamsandwich ham_use !
 
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <reapi>

public plugin_init()
{
    
// Load plugin 
    
register_plugin("[Entity] Chat Printer""1.0""LiZou Mapper")

    
// Think 
    
register_think("game_cprinter""CGameChatPrinter")

    
register_clcmd("say /test""clcmd_test");
}

public 
clcmd_test(id)
{
    new 
ent = -1;
    while( (
ent=engfunc(EngFunc_FindEntityByStringent"classname""game_cprinter")) > )
    {
        
DLLFunc(DLLFunc_Thinkent);
    }
}

public 
CGameChatPrinter(Entity)
{
    new 
Message[64], Spawnflags
    
// Get message from entity 
    
get_entvar(Entityvar_messageMessagecharsmax(Message))

    
// Get spawnflag from entity 
    // get_entvar(Entity, var_spawnflags, Spawnflags)

    
client_print_color(0print_chat"%s"Message)

    
// Print chat for player 
    /*if(Spawnflags == 0)
        client_print_color(Entity, print_chat, "%s", Message)

    if(Spawnflags & 1)
        client_print_color(0, print_chat, "%s", Message)

    if(Spawnflags & 2)
        Util_RemoveEntity(Entity)*/
}

public 
Util_RemoveEntity(const Entity)
{
    
engfunc(EngFunc_RemoveEntityEntity)


try to call think manually..

and btw Message should be string not an integer.

LiZou Mapper 08-10-2020 21:37

Re: Problem with hamsandwich ham_use !
 
Quote:

try to call think manually..

and btw Message should be string not an integer.
not working

LiZou Mapper 08-10-2020 21:38

Re: Problem with hamsandwich ham_use !
 
Like in client side :
PHP Code:

/* 
    ==== CONSOLE ENTITIES ====
    They do stuff in the console.
*/

#include "extdll.h"
#include "util.h"
#include "cbase.h"

class CTriggerConsolePrinter : public CBaseEntity
{
public:
    
void Spawn();
    
void KeyValue(KeyValueData *pkvd);

    
void Use(CBaseEntity *pActivatorCBaseEntity *pCallerUSE_TYPE useTypefloat value);

private:
    
string_t m_iszMessage;
};

LINK_ENTITY_TO_CLASS(trigger_conprintCTriggerConsolePrinter);

void CTriggerConsolePrinter::Spawn()
{
    
// Nothing
}

void CTriggerConsolePrinter::KeyValue(KeyValueData *pkvd)
{
    if (
FStrEq(pkvd->szKeyName"conmessage"))
    {
        
m_iszMessage ALLOC_STRING(pkvd->szValue);
        
pkvd->fHandled TRUE;
    }

    else
        
CBaseEntity::KeyValue(pkvd);
}

void CTriggerConsolePrinter::Use(CBaseEntity *pActivatorCBaseEntity *pCallerUSE_TYPE useTypefloat value)
{
    
ALERT(at_console"%s"STRING(m_iszMessage));



HamletEagle 08-11-2020 03:18

Re: i can't create new entity game_cprinter
 
You can't create a new entity out of thin air. It needs to be defined in the game code first. You can try creating a module and using LINK_ENTITY_TO_CLASS to create a new entity type.

LiZou Mapper 08-13-2020 23:05

Re: i can't create new entity game_cprinter
 
Quote:

Originally Posted by HamletEagle (Post 2713822)
You can't create a new entity out of thin air. It needs to be defined in the game code first. You can try creating a module and using LINK_ENTITY_TO_CLASS to create a new entity type.

thanks
i'm understand :)


All times are GMT -4. The time now is 13:51.

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