A few questions about events and game receive url response.

Users who are viewing this thread

Hello. I would be happy if someone helped me answer a few questions.


Im currently working at user management  and I don't know how to do few things.

Assume that game_receive_url_response receives data in the form like this "1|10|3|0|xyz|blablabla" (Im even right?)

How game know that  (assign, ":unique_id", reg2), is  for example 10


Ok that was first question .


My second question sounds like this :


I want create ban system which use  kicks after join to server.

In my database I have column "banned" . If its 0 = false  1=true.


So I add this
Code:
(assign, ":banned", reg4),
into game_receive_url response.


After this I need to add operation to kick. (in game_receive_url_response)

so all looks like this

Code:
             (assign, ":banned", reg4),
            
              (player_is_active, ":local_Id"),
              (player_get_unique_id, ":uid", ":local_Id"),
              
              (eq, ":Unique_Id", ":uid"),
####

(kick_player, ":uid"),

###
But I need to call operation (kick player) only if  banned=1. How I can do this?



My last question for now .

There is way to use  for example {reg4} from game_receive_url_response in another script ?




 
Responses

Let's say your PHP responds

"50|200|1000|2|55|test|22|ja"

50 = reg0
200 = reg1

reg(X) = Basically, reg and the value will retrieve the X'th integer of the response.

test = s0
ja = s1

s(X) = Basically, s and the value will retrieve the X'th string of the response.



If Operations

You want to check if a value is equal to another? You have your local value ":banned" which is either 0 = no ban or 1 = is banned.
That's where you are using try_begin

(try_begin),
    (eq, ":banned", 1),
    #Here your kick & ban operations
(try_end),

That's what try_begin would look like in if sense
If ":banned" = 1 Then
yourstuff
End If

So you insert that try_begin block, it basically means, only if the :banned value is equal to 1 then the things inside will happen otherwhise not and the script will continue.



Storing Values

When you receive a value from a script or here for you in this example you receive the value from receive_url_response you can't use it somewhere else. You store the value as a local variable which only will be able in this script.

How to use the value then? It is not that hard actually. First off, when a player connects he get's a unique player ID. This player ID makes you able to always seperate this special player from all other ones. If you want to store, in this example now, the banned value you need to use slots.

module_constants.py

slot_player_coop_opened_chests_end

add below that this: slot_player_is_banned

now you do:
(player_set_slot, ":player_id", slot_player_is_banned, reg4),
on your receive_url_response.

This means, the players "value"/"slot" slot_player_is_banned is always either 1 or 0 depending on what he get's from the script.
How to check now what value a player has?

(player_get_slot, ":value_of_slot", slot_player_is_banned, ":player_id"),

this will load the value of this players slot_player_is_banned into ":value_of_slot" and you can work with it.

Keep in mind: If the player disconnects you should reset all values on the player or just overwrite on connect so if a new player connects he won't get the banned even tho he is not. Also, slots, for example: Agent Slots. They vanish if the agent dies. A player is the real player and he controls the agent which moves and fights. If that agent dies his slots are vanishing. The player slots will always be the same until the player disconnects.
 
domipoppe said:
Responses

Let's say your PHP responds

"50|200|1000|2|55|test|22|ja"

50 = reg0
200 = reg1

reg(X) = Basically, reg and the value will retrieve the X'th integer of the response.

test = s0
ja = s1

s(X) = Basically, s and the value will retrieve the X'th string of the response.



If Operations

You want to check if a value is equal to another? You have your local value ":banned" which is either 0 = no ban or 1 = is banned.
That's where you are using try_begin

(try_begin),
    (eq, ":banned", 1),
    #Here your kick & ban operations
(try_end),

That's what try_begin would look like in if sense
If ":banned" = 1 Then
yourstuff
End If

So you insert that try_begin block, it basically means, only if the :banned value is equal to 1 then the things inside will happen otherwhise not and the script will continue.



Storing Values

When you receive a value from a script or here for you in this example you receive the value from receive_url_response you can't use it somewhere else. You store the value as a local variable which only will be able in this script.

How to use the value then? It is not that hard actually. First off, when a player connects he get's a unique player ID. This player ID makes you able to always seperate this special player from all other ones. If you want to store, in this example now, the banned value you need to use slots.

module_constants.py

slot_player_coop_opened_chests_end

add below that this: slot_player_is_banned

now you do:
(player_set_slot, ":player_id", slot_player_is_banned, reg4),
on your receive_url_response.

This means, the players "value"/"slot" slot_player_is_banned is always either 1 or 0 depending on what he get's from the script.
How to check now what value a player has?

(player_get_slot, ":value_of_slot", slot_player_is_banned, ":player_id"),

this will load the value of this players slot_player_is_banned into ":value_of_slot" and you can work with it.

Keep in mind: If the player disconnects you should reset all values on the player or just overwrite on connect so if a new player connects he won't get the banned even tho he is not. Also, slots, for example: Agent Slots. They vanish if the agent dies. A player is the real player and he controls the agent which moves and fights. If that agent dies his slots are vanishing. The player slots will always be the same until the player disconnects.


Thank you for your comprehensive answer.
In the mean Time I do some test .
Kicking players in game_receive_url_respond is probably too early , because logs give me info about unknown player id.and I need to create New  script using constants  method.  Im right?


I try too add kill count or add team score(for tests)  in game_receive_url_response.it works but only players which join after me can see changes.  Im doing it in wrong place or There is no way to sync it?

 
To sync values like score from server to client you need to do multiplayer_events.
But, if you check how Native does it you should be able to just use that method.

I don't know what you mean.
Make a trigger (ti_on_player_joined, 0, 0,....
(store_trigger_param, ":player_id", 1),
(assign, reg1, ":player_id"),
(send_message_to_url, "@http://localhost/yourscript.php?playerid={reg1}"),

Then on PHP script

$player_id = $_GET["playerid"];

then just

echo $player_id|yourvalue|othervalue....;

then on receive_url

reg0 = player id.
 
Thanks for let  me know what is slot_xxx  in module_constats.py  :grin:

Ok. Now I start trying to equiping players from database . I would to use easiest method which is possibile and make it work.


Ok firsly I create reciving  data on game_receive_url_message


Code:
  ("game_receive_url_response",
    [
	(store_script_param, ":num_integers", 1),
    (store_script_param, ":num_strings", 2),  
##
##
##	  
        ####ASSIGN STUFF BEGIN
        (try_begin),
		  (server_add_message_to_log,"@Game Receive Data Starts"),
		  
		  ####ASSIGN STUFF BEGIN

              (assign, ":uid", reg0),
			  (assign, ":troop_id", reg2),
			  (assign, ":lid", reg4),
			  
			  (player_set_slot, ":lid", slot_player_weapon1, reg1),
			  (player_set_slot, ":lid", slot_player_lid, reg4),   ### FOR USE LOCAL ID IN THE FUTURE
           
		   (try_end),
		   
		  ###ASSIGN STUFF END
		 
	]), 


Code:
## module_constants_py

slot_player_is_banned = 41
slot_player_lid = 42


Note: lid is local_id / player_id .

Okey so I have slots which I can use in other part of module_system.



Now I have few ways to equip items . For example troop_add_item  +  troop_equip_items or troop default items .

Way with troop default items seems to be more easy but I really don't know where to start.


I found something about default_item  in module_scripts.py but I dont see any reference how I can edit to make it work with url response and my slots.


Code:
  ("cf_multiplayer_is_item_default_for_troop",
   [
     (store_script_param, ":item_no", 1),
     (store_script_param, ":troop_no", 2),
     (assign, ":default_item", 0),
     (try_begin),
       (neg|is_between, ":item_no", horses_begin, horses_end),
       (neg|is_between, ":item_no", oim_horses_begin, oim_horses_end),
       (troop_get_inventory_capacity, ":end_cond", ":troop_no"), #troop no can come -1 here error occured at friday
       (try_for_range, ":i_slot", 0, ":end_cond"),
         (troop_get_inventory_slot, ":default_item_id", ":troop_no", ":i_slot"),
         (eq, ":item_no", ":default_item_id"),
         (assign, ":default_item", 1),
         (assign, ":end_cond", 0), #break
       (try_end),
     (try_end),
     (eq, ":default_item", 1),
     ]),





If I would use  other option with agent_equip and add item on game receive url response I should do this something like this:


Code:
  ("game_receive_url_response",
    [
	(store_script_param, ":num_integers", 1),
    (store_script_param, ":num_strings", 2),  
##
##
##	
        (try_begin),
		  (server_add_message_to_log,"@Game Receive Data Starts"),
		  
		  ####ASIGN STUFF BEGIN

              (assign, ":uid", reg0),
			  (assign, ":troop_id", reg2),
			  (assign, ":lid", reg4),
			  
			  (player_set_slot, ":player_id", slot_player_weapon1, reg1),
           
		  ###ASIGN STUFF END
		  	   
              (player_is_active, ":uid"),
			  (player_get_agent_id, ":agent_id", ":uid"),
			  (agent_get_troop_id, ":troop_id", ":agent_id"),
			  (try_end),
			  
			  (troop_add_item, ":troop_id", 17, 0),   ##  currently static item for debug....
			  
		(troop_equip_items, ":troop_id"),	  
	        
              (server_add_message_to_log,"@Now player should equip weapon with ID 17"),			
			  
			  (try_end),
##
##			  
			  (else_try),
	
			  (troop_set_class, ":troop_id", 1),
			  
			  (try_end),	
	    (try_end),	
			]),



But there I have problem like "How I can get troop_id , save it on database and use it in game_receive_url_respond for every unique_id"


Of course in this way I need to delete some stuff like equipment selection/troop choose but now idk how to work with troop_id.


Thanks for any advice and  reading this wall of text if anyone do this.

Cheers
 
You can't use troop functions on agents or players.

Player, Agents and Troops have their own operations.
- player_* / agent_* / troop_*....
You can't mix them up but you can work around with for example agent_get_player_id or player_get_agent_id.

If you want to equip an item, simply do (agent_equip_item,...)
weapon slots etc can be found in constants.

Giving a troop for example Swadian Sergeant some items will result that they will spawn with it if you do spawn_agent, "trp_swadian_sergeant".

Also look at player_add_spawn_item
 
domipoppe said:
You can't use troop functions on agents or players.

Player, Agents and Troops have their own operations.
- player_* / agent_* / troop_*....
You can't mix them up but you can work around with for example agent_get_player_id or player_get_agent_id.

If you want to equip an item, simply do (agent_equip_item,...)
weapon slots etc can be found in constants.

Giving a troop for example Swadian Sergeant some items will result that they will spawn with it if you do spawn_agent, "trp_swadian_sergeant".

Also look at player_add_spawn_item

I need to add items/raise skills for uniqie player troop everytime he joins the server .



Code:
(try_begin),   ## Items for player troop
	            (troop_raise_skill, ":reg5", skl_athletics, 10),
	            (troop_add_item, ":reg5", 42, 0),
				(troop_add_item, ":reg5", ":weapon", 0),
				
				(troop_equip_items, ":reg5"),
				(player_set_troop_id, ":lid", ":reg5"),  ##set player to his troop 
	(try_end),




But I'm not exacly sure how to  make it work with native troops/agents spawn.


For example there is one of native script


Code:
 ("mp_set_player_troop_id",
    [ 
	  (store_script_param, ":player_no", 1),
	  (store_script_param, ":troop_id", 2),
	  (store_script_param, ":do_sync", 3),
	  (player_set_troop_id, ":player_no", ":troop_id"),
	  (try_begin),
	    (eq, ":troop_id", -1),
		(call_script, "script_multiplayer_clear_player_selected_items", ":player_no"), # just to make sure
	  (else_try),
		(call_script, "script_multiplayer_set_default_item_selections_for_troop", ":player_no", ":troop_id"),
	  (try_end),
	  # server will do the same, so no need to send the new selections
	  (try_begin),
		(neq, ":do_sync", 0),
		(multiplayer_send_int_to_server, multiplayer_event_change_troop_id, ":troop_id"),
	  (try_end),
  ]),
For example I have player troop in reg1
I need to create slot for it and use it somewhere?

I have no idea.

I do not know yet which script can  overwrite my one from_receive_url response yet.



 
If you want to give players different skills then you need to use troops yes.
But for that it would require you to create like 200 (or whatever max player of you is) Temp Troops on which you set the items and skills then.
Then you set the troop for the player and spawn him.

Spawning is done with agent_spawn. The trigger ti_on_agent_spawned also exists.
 
Back
Top Bottom