AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   spawn objects/entities [Help] (https://forums.alliedmods.net/showthread.php?t=208148)

striker07 02-10-2013 11:45

spawn objects/entities [Help]
 
I come from amxmodx and just started learning sourcepawn, still got a long road ahead.
But I was wondering, is it possible to drop/spawn an object in the map? and is it possible to register touches and thinks for the object/ent?
Will it also work for CS:GO?

If possible, could someone show me a simple hook to the events?

ajr1234 02-10-2013 22:27

Re: spawn objects
 
Yes, it is possible. You'll want to look into CreateEntityByName and HookEntityOutput. There is an object spawning plugin in the forums somewhere-- search for it. It's for L4D2 but the concept/code doesn't change. As for detecting touch, you may need to hook the entity's OnStartTouch output.

striker07 02-11-2013 22:21

Re: spawn objects
 
Ok, got it.
Just a lil example here:
PHP Code:

public Spawn_Object(clientidFloat:Origin[3])
{
    
EntIndex CreateEntityByName("testentity");
    
HookEntityOutput("testentity""test"TestEntCallback); 
// when will TestEntCallback be called? & only once or continues (like a think in amxx)? its depended on what output name is right?)
 
    // Some code dressing the object/ent...
    // ...
 
    // spawn it
    
    
SetEntDataVector(EntIndexoffset(position vector), const Float:Origin[3]);
// where can i find all offsets?
    
new bool:Spawnsucces DispatchSpawn(EntIndex);
    if( !
Spawnsucces )
    {
        
Spawn_Object()
    }
 
}
 
public 
EntityOutput(const String:"test"calleractivatorFloat:0.0)
{
 


I can't find anything for OnStartTouch, where can i find info on that/in what is it included?
And can i not choose coordinates to spawn the entity? like for example when a player died get his origin and spawn the entity there:

get origin vector of the player: native GetClientAbsOrigin(client, Float:vec[3]);
but how do i set that vector as the spawnpoint for the entity, with SetEntDataVector?

mcpan313 02-12-2013 03:12

Re: spawn objects
 
PHP Code:

stock CreateSomeEntity(clientFloat:vecOrigin[3])
{
    new 
entity CreateEntityByName("entity_name");
    if (
entity != -1)
    {
        
// you can using sm_dump_datamaps / sm_dump_netprops server command got all offsets.
        
SetEntPropVector(entityProp_Data"m_vecOrigin"vecOrigin);
        
// your code here.
        
        
if (DispatchSpawn(entity))
        {
            
// if you can't find OnStartTouch output, using SDKHooks
            // http://hg.alliedmods.net/sourcemod-central/file/tip/plugins/include/sdkhooks.inc
            
SDKHook(entitySDKHook_StartTouchEntity_OnStartTouch);
        }
    }
}

public 
Entity_OnStartTouch(entityother)
{
    
// your code.



ajr1234 02-12-2013 11:26

Re: spawn objects
 
You can just use TeleportEntity() to teleport the object. You can hook onstarttouch like this:

Code:

HookSingleEntityOutput(entity, "OnStartTouch", ontouch);

public ontouch(const String:output[], caller, activator, Float:delay)
{
}

No need to add a dependency to your plugin.

striker07 02-12-2013 12:31

Re: spawn objects
 
Spoiler

Ok thanks mcpan,
- I'm not sure how to use sm_dump_datamaps/netprops. tryed on my server as admin but it said unrecognized command?
I'll try in server console when i get home.

- What is the diffrence between these 2 hooks: SDKHook_StartTouch, SDKHook_Touch? SDKHook_Touch wil continuisly call itself as long as player is touching it and starttouch only once everytime a player touches it?

- Can i use this in Entity_OnStartTouch to store in the clientindex of the player touched it without replacing the entity index?
SetEntProp(entity, Prop_Data, "PropField_Integer", client);

Spoiler

-In order to teleport an entity, does it need to be already in the game before doing so?

- With that hook the callback would only be performed once and then delete itself right? then what exactly is the diffrence between "HookSingleEntityOutput" and "SDKHook"?

- What do you mean by adding a dependency to the plugin?


This is what i have thusfar(I hope there are not to many mistakes in it):
PHP Code:

#include <sourcemod>
#include <sdktools>
 
new LaserSpriteHalosprite;
new 
Handle:g_hEntSpawnTimer
 
public Plugin:MyInfo 
{
    
name "",
    
author "striker07",
    
description "",
    
version "1.0"
    
url ""
};
 
public 
OnPluginStart()
{
 
    
LoadTranslations("common.phrases"); 
 
    
//Precache
    
LaserSprite PrecacheModel(const String:"sprites/bluelaser1"bool:preload=true); 
    
Halosprite PrecacheModel(const String:"sprites/plasmahalo"bool:preload=true); 
 
    
HookEvent("player_death"Event_PlayerDeath); 
 
}
 
public 
Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
victim_id GetEventInt(event"userid");
    new 
attacker_id GetEventInt(event"attacker");
 
    new 
victim GetClientOfUserId(victim_id);
    new 
attacker GetClientOfUserId(attacker_id);
    new 
Float:Origin[3];
 
    
GetClientAbsOrigin(victimFloat:Origin[3]); 
 
    
CreateSomeEntity(victimFloat:Origin[3]);
 
}
stock CreateSomeEntity(clientFloat:Origin[3]) 

    new 
entity CreateEntityByName("my_entity"); 
    
//new EntData[3];
 
    
if (entity != -1
    { 
        
// you can using sm_dump_datamaps / sm_dump_netprops server command got all offsets. 
        
SetEntPropVector(entityProp_Data"m_vecOrigin"Float:Origin); 
 
 
        
SetEntityRenderMode(entityRENDER_TRANSCOLOR); 
        
SetEntityRenderFx(entityRENDERFX_PULSE_SLOW);
        
SetEntityRenderColor(entityr=31g=191b=36a=160);
 
        
// your code here. 
        
new Float:BeamStartOrigin[3], Float:BeamEndOrigin[3], BeamColor[4];
        
Float:BeamStartOrigin Float:BeamEndOrigin Float:Origin;
 
        
Float:BeamStartOrigin[2] = (Float:Origin[2] + 125);
        
Float:BeamEndOrigin[2] = (Float:Origin[2] - 45);
 
        
BeamColor[1] = 173;
        
BeamColor[2] = 156;
        
BeamColor[3] = 28;
        
BeamColor[4] = 210;
 
        
TE_SetupEnergySplash(const Float:Origin, const Float:Origin+50);
 
        
TE_SetupBeamPoints(const Float:BeamStartOrigin, const Float:BeamEndOrigin
              
LaserSpriteHalosprite,
              
010Float:0.8,  
              
Float:25Float:20_,
              
Float:5, const BeamColor185);
 
 
        
Handle:g_hEntSpawnTimer CreateTimer(Float:0.8Timer:SpawnEntityany:entity);
        if( 
Handle:g_hEntSpawnTimer == INVALID_HANDLE )
        {
            
PrintToServer("Failed to start time, Ent. will not spawn");
      } 

public 
Timer:SpawnEntity(entity)
{
    if (
DispatchSpawn(entity)) 
    { 
    
// if you can't find OnStartTouch output, using SDKHooks 
    // http://hg.alliedmods.net/sourcemod-central/file/tip/plugins/include/sdkhooks.inc 
        
SDKHook(entitySDKHook_StartTouchEntity_OnStartTouch); 
    }
}
public 
Entity_OnStartTouch(entityclient

 
//Can i use this to store in the clientindex of the player touched it?
    
SetEntProp(entityProp_Data"PropField_Integer"client); 



ajr1234 02-12-2013 23:55

Re: spawn objects
 
Quote:

Originally Posted by striker07 (Post 1893072)
-In order to teleport an entity, does it need to be already in the game before doing so?

- With that hook the callback would only be performed once and then delete itself right? then what exactly is the diffrence between "HookSingleEntityOutput" and "SDKHook"?

- What do you mean by adding a dependency to the plugin?

I prefer to teleport the entity after DispatchSpawn.
PHP Code:

TeleportEntity(entityOriginNULL_VECTORNULL_VECTOR); 

HookSingleEntityOutput will hook a single entity's output until it is unhooked. Simply put, HookSingleEntityOutput affects a particular (single) entity, and HookEntityOutput affects all entities of the classname. The optional fourth parameter to HookSingleEntityOutput() will allow you to fire the callback once or indefinitely.

Adding a dependency means requiring the server to have other plugins/extensions installed in order for your plugin to work. If you want to keep your plugin dependency free (as in, no other extensions need to be installed for your plugin), then stick to HookSingleEntityOutput(). Keep in mind that the latest dev branch (SM 1.5) comes with SDK Hooks included, but the stable SM branch does not.

striker07 02-13-2013 13:14

Re: spawn objects
 
Thanks for clarifying

Quote:

Originally Posted by ajr1234 (Post 1893387)
HookSingleEntityOutput will hook a single entity's output until it is unhooked. Simply put, HookSingleEntityOutput affects a particular (single) entity, and HookEntityOutput affects all entities of the classname. The optional fourth parameter to HookSingleEntityOutput() will allow you to fire the callback once or indefinitely.

- Just to be sure;
With the optional fourth param(bool) false, HookSingleEntityOutput() will not act like a think, it just means that the native isnt gonna unhook itself after it has performed his actions and will never do so unless you code it somewhere in the plugin?

- and here: (forgive me if this question sounds abit newb but i'm coming from amxx and these tags confuse me sometime)
Code:

HookSingleEntityOutput(entity, "OnStartTouch", ontouch);
 

public ontouch(const String:output[], caller, activator, Float:delay)  //What data would be in these parameters,
//can I change the names and remove the tags here?
{
}

- I just tryed the sm_dump commands from the server console and it worked, but i can't find the fileback. where exactly will it be stored to?
Code:

19:01:27 sm_dump_netprops test.txt
19:01:27 L 02/13/2013 - 19:01:30: rcon from "78.22.24.168:51337": command "sm_dump_netprops test.txt"
19:01:27 L 02/13/2013 - 19:01:30: rcon from "78.22.24.168:51337": command "sm_dump_netprops test.txt"


MasterOfTheXP 02-13-2013 14:59

Re: spawn objects
 
Quote:

Originally Posted by striker07 (Post 1893715)
where exactly will it be stored to?

By default, netprops and datamaps get dumped to the root game directory (e.g. cstrike/)

ajr1234 02-13-2013 17:42

Re: spawn objects
 
Quote:

Originally Posted by striker07 (Post 1893715)
- Just to be sure;
With the optional fourth param(bool) false, HookSingleEntityOutput() will not act like a think, it just means that the native isnt gonna unhook itself after it has performed his actions and will never do so unless you code it somewhere in the plugin?

- and here: (forgive me if this question sounds abit newb but i'm coming from amxx and these tags confuse me sometime)

Your callback will be fired whenever an entity touches the hooked entity, provided that both the entity and the hooked entity are 1) networked, and 2) resolve collisions. If you want the hook to be removed after a single callback, then set the fourth param to true:
Code:

HookSingleEntityOutput(entity, "OnStartTouch", ontouch, true);
In other words, let us assume that you hooked a trigger_multiple entity. Whenever the player touches the trigger_multiple, your callback will be fired. The callback will not fire continuously (it will fire once when first touched). However, if the player moves out of the trigger and back in, your callback will be fired again. If you want the callback to fire only once (forever), you can either set the fourth param to true or unhook the hook manually in your code. If you do not unhook the hook, the hook will be removed automatically when the entity in question is destroyed.

As for your second question, the "output[]" character array will contain the name of the output (i.e. "OnStartTouch"). The caller is generally the entity that was touched, and the activator is the entity that did the touching. The delay param applies if the output was fired with a delay (i.e. the map developer triggered a delayed I/O chain).

Lastly, no, you cannot get rid of any params from the callback, as that would screw up the stack.


All times are GMT -4. The time now is 15:54.

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